added saving output to CSV file