write file with rename