Using Java String buffer instead of CFFILE to convert a query to CSV file for output is much faster. Below is the code that is required, change the fileds and table name according to your dataabse.
<!--- Writing query to a CSV file using JAVA STRING BUFFER --->
<!--- get the details in a query, always use JOINS if you have more than one table --->
<cfquery name="get_records" datasource="xxxx">
select field1, field2, field3 from Table
</cfquery>
<!--- Give the location of your file where you will be writing the data --->
<cfset TempFile = (ExpandPath("dir") & ".csv") >
<!--- Create a STRING BUFFER to hold the output --->
<cfset QueryOutput = CreateObject("java","java.lang.StringBuffer").Init() >
<!--- append the column headers to string buffer, you also need to add a link break --->
<cfset QueryOutput.Append("field1, field2, field3" & chr(13) & chr(10))>
<!--- get an intial ID, so that we know when to append --->
<cfset Queryid = -1 >
<!--- loop through the query, and append the records to the buffer --->
<cfloop query="get_records">
<cfif (get_records.field1 NEQ Queryid)>
<cfset Queryid = get_records.field1 >
<cfset QueryOutput.Append("#get_records.field1#, #get_records.field2#, #get_records.field3#" & chr(13) & chr(10))>
</cfif>
<cfset QueryOutput.Append("#get_records.fields1#, #get_records.field2#, #get_records.field3#" & chr(13) & chr(10))>
</cfloop>
<!--- Write the string buffer to the file, suing ToString ---->
<cffile action="write" file="#TempFile#" output="#QueryOutput.ToString()">
<!--- End of writing query to a CSV file --->