Writing to files on a remote volume doesn't work...

My script writes some HTML code to a file. Essentially, it’s this:

 
set filename to choose file

set fileSpec to filename as file specification

set eof fileSpec to 0

write "some text info" to fileSpec

Everything works fine when “filename” is on a local drive, but when it’s on a remote drive the script fails. (“index.html” can not be found)

Any ideas?