Writing the files with templates