JavaScript cannot safe files on the client's computer. A nice tool to use is Downloadify (
https://github.com/dcneiner/Downloadify ). It's a little Flash application that you can easily style as a button. Using JavaScript you can feed it with a text and then by clicking on it it will allow the user to save the file.
air