write file atomic