code that converts stats data to CSV file