Writes to csv file