How to export data to a CSV file