Write new file to a temporary directory and move it afterwards.