added function to write tidy data to csv