Check out this useful post from Cyril Fauvelle on the ins and outs of the dreaded MScriptUtil.
This kind of stuff is why I reserve API programming for only the knottiest of tasks. maya.cmds won't clean-exit your Maya session if you reverse two lines by accident. However, sometimes there's no alternative... Here's hoping API 2.0 matures quickly and we can all forget all of this pointless distraction.