added a function to write to the csv