Certainly check the compass and possible interference, but if the issue is solely wandering as you near a waypoint, I'd also look at the A/P settings. There are three main settings to all A/Ps
1. Yaw (or XTE - Cross Track Error); or how far from the courseline before corrective action is taken.
2. Rudder - how much rudder to apply
3. Counter-rudder. How much counter-steer to apply to straigten the course after rudder-correction has been made.
From your brief description, guessing the issue is in the XTE/Yaw setting - the boat is allowed to get too far off the rhumbline which is fine until the angle closes-in at the waypoint, then it just takes too much to course-correct (Rudder is likely too low too).
These are just guesses. I can tell you from experience that adjusting an A/P is an exercise in restraint and patience. As the attached diagram from Comnav shows, if the boat is swinging/zig-zagging, reduce settings which is a bit counter-intuitive.
Good luck. Please update when you figure it out.
Peter
EDIT - on the third Comnav diagram - "Not enough rudder," they should also show the boat over-shooting the mark due to too little rudder, then slowly drifting to the trackline to next waypoint. In my experience, this is more common for 'too little rudder' than the scenario they show. But you have to play with it. Best is to have someone at the helm and you bury your head to observe the rudders being actuated. You will learn a lot, at least until the blood runs out of your brain....
View attachment 129939