Save to a temporary file, then copy the result over on success
I thought we were already doing this, but apparently that only
was done for remote urls, back in the days we still supported that.
The temporary file is saved in the tmp dir, and then copied over.
We even make a safety copy of the original file if it exists before
doing the copy. This should make saving over network drives faster
and more reliable, as well as saving in general more robust.
BUG:366765,357132,355726