Fix issue #6701. Use shutil.move instead of os.rename.

Here's a simple fix for issue #6701, I'd like some review thoughts on the us of shutil here. Using  os.rename was nice as the rename is atomic - however I guess that is not going to be possible to get across filesystems. I did wonder about simply rewriting the file in place and dispensing with temp files altogether. Thoughts?