Creates a CSV file based on mysql query