Write output files only once