writes final csv file