As of HTML5, you can use a combination of data: URL and download attribute. For example,
<a href="data:text/plain;charset=UTF-8,Hello%20World!" download="filename.txt">Download</a>
Or, programatically,
<a id="programatically" href="#" download="date.txt">Download</a>
$("a#programatically").click(function() {
var now = new Date().toString();
this.href = "data:text/plain;charset=UTF-8," + encodeURIComponent(now);
});
See it here.
Unfortunately, download attribute is not fully supported and data: URLs are in good track.
Now, for a better cross-browser support you will need to create the file dynamically at server-side.