You can use the full power of the File System API only if you can get the user to select the file you need to write to. You can use cookies in your code if that is not your case.
The saveData
function can save whatever the string you need in a cookie. The file will be there even after you close the browser (set for 30 days in my example).
The loadData function returns the data you saved in a previous session.
Use $cookies
provider in Angular if you use it. It sums the things up in a nicer way.
You will see that cookies can do much more things including saving multiple data sets in multiple files if you explore bit more by googling about it.
function saveData(searchQuery) {
var d = new Date();
d.setTime(d.getTime() + (30*24*60*60*1000));
var expires = "expires="+d.toUTCString();
document.cookie = "mySearch=" + searchQuery + "; expires=" + expires;
};
function loadData() {
return document.cookie;
}