write output file to csv