Hold down the command (Apple) key once you have started dragging the items to the Dock. The command key will prevent the Dock items from moving around on you. I say to start holding command after you have started dragging so you don't de-select one of the intended target files instead of starting the drag process.
I agree though, there should be a Dock undo.
As for stew's first suggestion- You're probably better off trashing the plist file rather than trying to edit out those 40+ items. Perhaps setup your Dock precisely how you want it, then make a copy of ~/Library/Preferences/com.apple.Dock.plist so if you have to trash it, you don't have to fuss with editing the plist file or setting the Dock back up the way you want it. Just replace the "bad" one with the "good" one, relaunch the Dock however you see fit (log out, kill the Dock's process etc) and go on about your business.