Open temporary file r+ so that it does not need to be opened again

Note that this works on Unix, but not Windows
Revert "Open temporary file r+ so that it does not need to be opened again"

This reverts commit d9706341b646350bdec99059197a2b0b41b9c5b3.
On second thought, I am not sure this is such a good idea.