This question is very basic, but somehow absurdly difficult to find an answer for, because everything you find explains how to save the buffer, and I'm not interested in making new buffers or saving the current buffer.
I had been using (for years!) some pretty ugly code that requires vim to be built with python in order to work:
if has('python')
python << EOF
from os.path import expanduser
f = open('/path/to/file', 'w')
# print f
w = vim.eval("varname")
f.write(w)
f.close()
EOF
That snippet uses the simple-to-use python file api to write the contents of vim variable varname
into /path/to/file
.