The problem is, i want to save a text file (or anything) in the local system using javascript.
You can't write to the user's file system. But you initiate a file download that the user can then save wherever they'd like.
In PHP, you can just use
header('Content-Disposition: attachment; filename=file.txt');
echo('File contents');
There is no practical real world way to create a local file. However if you want to to just store data locally then try these two methods.
The old way:
http://www.w3schools.com/js/js_cookies.asp
The new way:
http://diveintohtml5.ep.io/storage.html
Alternatively, you could create a file with php and serve it out to the user.