Much better to do this with server-side coding (PHP/ASP/JSP/etc.).
That way you can have the server-side script *tell* the browser to download the file, rather than just display it.
I think the best you could do with JS would be to copy the text to the clipboard (and now we are talking browser dependencies) so that you can then just paste it into a text file.
This *COULD* be done with MSIE, assuming that the browser user is willing to give special (dangerous!) permissions to the web site in question. Normally, you would only do this in an inTRAnet situation, not inTERnet.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.