I followed this thread on and off and feel some comments should be made on the topic of outputting to files.
It's true that OPEN only streams ASCII files. It's also true that WRITE-LINE can only write strings to a file, but it is certainly possible to write any data type. It just depends on the function used to write the data. Let's take a look at them by using an example: WRITE-LINE, PRINC, PRINT and PRIN1.
First make some non-string data, in this case a list:
(setq alst '(1 2 3 4 5))
-> (1 2 3 4 5)
Then create a file:
(setq fn (open "C:\\abc.txt" "w"))
-> #<file "C:\\abc.txt">
Now try the various functions to write the data. To keep track of which function was used, we'll write the functions as a string before writing the data. We'll also use a newline character to see how they each treat control characters.
First WRITE-LINE. As Mark pointed out, it only handles strings so we'll need to convert the list to a string using VL-PRINC-TO-STRING:
(write-line "\nwrite-line:" fn)
-> "\nwrite-line:"
(write-line (vl-princ-to-string alst) fn)
-> "(1 2 3 4 5)"
Then PRINC, PRINT and PRIN1. These functions write any data types - just like they would at the command line:
(princ "\nprinc:" fn)
-> "\nprinc:"
(princ alst fn)
-> (1 2 3 4 5)
(print "\nprint:" fn)
-> "\nprint:"
(print alst fn)
-> (1 2 3 4 5)
(prin1 "\nprin1:" fn)
-> "\nprin1:"
(prin1 alst fn)
-> (1 2 3 4 5)
Now close the file and open it (here just using Notepad):
(close fn)
-> nil
(startapp "notepad.exe" "C:\\abc.txt")
-> 33
The file should look like this (first blank line included):
write-line
(1 2 3 4 5)
princ:(1 2 3 4 5)
"\nprint:"
(1 2 3 4 5) "\nprin1:"(1 2 3 4 5)
WRITE-LINE: Writes its string argument with a trailing newline character. Control characters are output as their ASCII representation; a newline character creates a linefeed, a tab character creates a tabulation etc.
Notice that the automatic newline character is put at the end of the string. The first blank line in the example came from the explicit "\n"-character, but the second blank line was caused by the combination of WRITE-LINE's newline and PRINC' explicit newline character.
PRINC: Works like WRITE-LINE except that it does not create a new line. Also, neither PRINC, PRINT nor PRIN1 are limited to outputting strings.
PRINT: Outputs the literal value of its argument, which means that strings become quoted and control characters are expanded into their control character codes. It also prints a leading newline character and a trailing space. Notice that "\nprint:" was output on a new line and that it has a trailing space (put the cursor at the end of the line to see it).
PRIN1: Works like PRINT, except that it doesn't print a leading newline character and a trailing space. Notice that the space before "\nprin1:" came from the previous PRINT statement and that PRIN1 did not jump to a new line.