Surging like that is almost always related to carb adjustment and governor adjustment. It can also be caused by fuel blockage in the supply lines though which usually happens under heavy engine load.
Check for cleanliness, wear, and proper adjustment.
If your engine is only surging at high rpm I would suspect a fuel blockage in the tank or a line or something of that nature. This would be the first thing to check.
If your engine is surging eradically and at all engine rpms/load conditions then I would suspect the governor/carb adjustment.
I can't recall off the top of my head which style governor the 5000 has but almost all governors work off tension balanced by engine demand.
The tension is supplied by centrifigal force using a fly weight assembly or by an actual spring.
If it has a flyweight assembly check for wear on the weights and general sloppiness of the assembly.
If everything looks good then its likely your carb just needs some cleaning and tuning.
Also make sure your ignition timing is correct and isnt bouncing all over the place (worn distributor parts).