Write new file to a temporary and move it afterwards.