And here is the new code that does just what I suggested -- saves both maximized and normal window positions for each monitor, and then for windows that have mysteriously stayed maximized but moved to a different monitor, those are first restored before they are remaximized. Other windows are left alone, which makes for much visual ugliness on screen. (it might be possible to improve this further by making window invisible before unaximizing and remaximizing but that as this is only running on monitor wakeup i think it's no big deal).
I am really excited to try this for real when i wake up tomorrow.
[ps. I have been testing it using nircmd to put monitors to sleep -- my earlier reports that this did not reproduce the problem were wrong; turns out i just needed to give the monitors at least 30 seconds or so to go into power saving mode before waking them up).
I will report tomorrow on real-world test of the tool.

[OLD FILE REMOVED SEE SUBSEQUENT POST]