I usually do not get the opportunity to use cffile to write files to the file system. Today, however, I got the chance to use action="write" while working on the beginnings of a code generator. The proof-of-concept code creates a CF file in a specific directory, much in the way Fusebox 5 generates its parsed files (in fact, Fusebox was my inspiration). The code generator uses a Java StringBuffer to store the contents of the file before writing it to the file system:

view plain print about
1<!--- Line feeds need a carriage return and a line feed character --->
2<cfset variables.crlf = chr(13) & chr(10)>
3<!--- A Java StringBuffer is more efficient than using a string variable. --->
4<cfset variables.contentBuffer = createObject("java", "java.lang.StringBuffer").init()>
5<!--- Add the contents of the file to the buffer. --->
6<cfset variables.contentBuffer.append('<cfset variables.message = "CF generated me!">').append(variables.crlf)>
7<cfset variables.contentBuffer.append('<cfoutput>##variables.message##</cfoutput>')>

Note the double pound signs inside the cfoutput tags. If I did not escape the pound signs by doubling them, CF would think variables.message is an actual variable that needed to be parsed. Once the content buffer contains the full contents of the file, cffile swings into action to create the physical CFM file:
view plain print about
1<!--- cffile needs an absolute path, so place the file in the current directory. --->
2<cfset variables.filePath = getDirectoryFromPath(expandPath("*.*"))>
3<cffile action="write" file="#variables.path#/myfile.cfm" output="#variables.contentBuffer.toString()#">
Opening up myfile.cfm we see:
view plain print about
1<cfset variables.message = "CF generated me!">