only write file if it has changed