Applescript:

If you need this file into a text editor, we would recommend adding a little flag to the file (called BOM: Byte Order Mark), so the text editor recognizes this is a utf-16 encoded file:

Applescript:

set f to (open for access file x)set eof of f to 0 --> empty file contents if needed--> now write the flagwrite ((ASCII character 254) & (ASCII character 255)) to f --> not as Unicode text--> now write the datawrite "foo"to f as Unicode text
close access f

We wrote 0xFE and 0xFF (in hex notation) as BOM, which is the rigth mark in Mac, while in a PC we would swap this as 0xFF and 0xFE (as well as all the other bytes).