Added Header for CSV file and error handling