Fix invalid file handles on Windows being accepted due to an incorrect check
Make tests pass for all supported save_to modes

This was really difficult because the windows API makes atomic file
operations REALLY difficult.