Use a tempfile in between the overwrite of the requested one
Make sure to provide a tempdir with a file pattern for BSD compatibility