Added writing to CSV file