I have no knowledge of the mirror but I will make some theoretical suggestions - which may be wrong.
A few mk4 owners have had problems with the right hand mirror .These were replaced under warranty. Some have solved the problem themselves with carefully targeted light lubrication. But I am not sure this is your problem.
How does the electric motor 'know' when it needs to stop? If there is only one motor and cog wheel it may run backwards and forwards by reversing the polarity so there may be two stop positions. There may be some sort of position sensor in the mirror that cuts power when the mirror is fully extended or fully retracted. Maybe this has become desynchronised or displaced. But the mechanism may be built in to the motor and not immediately obvious , or tripped by a lug on the cogwheel ,that maybe worked when first fitted but not tripping it now. Its also possible the broken cogwheel was the result of the motor over running previously , not the cause of the problem. It might be able to tolerate a certain amount of over run for a while without breaking or wearing out.
Another possibility is that power is cut by some sort of electrical device when it senses the motor is under strain because the mirror has reached its position. It would also give protection if the mirror is obstructed in some way, such as by ice. Maybe if there is such a device it has failed . But it need not be in the mirror itself,but elsewhere as part of complex electronics.
Does the mirror work ok if you use the manual mirror fold switch in the drivers door? Could the switch be faulty.? But i would have thought this would affect both mirrors.
Does the passenger mirror motor stop running as it should?
These things might help you isolate the cause .
If you dont mind some extra work, you could as a last test unplug the mirror wiring and using extension wires connect the left mirror to the right side wiring and then vice versa. If the problem migrates to the other mirror the problem may be central to the car internal wiring. If the same mirror continues to be faulty the fault lies within in the mirror and it may be easier to replace it. You may be able to get a second hand one for not much more than you paid for the cogs. There are used parts search web sites. Enter what you need for free and various breakers yards send you their price. A bit like a personalised ebay listing.
Or dont bother with the rewiring trick and replace it anyway. If it later proves both mirrors are ok you could re sell one and get some of your money back.