Convers query results to CSV with format flag