Copy file before writing, keeps file permissions intact