I'm not sure that would be the best idea.
JavaScript is vulnerable to attack, You'd be better of use a server side language such as
PHP or
ASP. They are quite easy to learn.
Although, if you would really like to use
JS. Have a look at this:
http://4umi.com/web/javascript/filewrite.htm
Or just google, JavaScript - Writing files.