Write data to csv file