Hi Håkan,
There's the currently undocumented File object that helps you do these kind of things easily. For pure JS data (strings, numbers, booleans, objects and arrays) you can then combine this with JSON for a simple and flexible way of storing and retrieving data from and to files.
So to store JS data, you would do something like this:
var data = [false, 1, 2, 3, 'four', { five: 6 }];
var file = new File(script.file.parent, 'file.json');
print(file);
// If file exists, we need to remove it first in order to overwrite its content.
if (file.exists())
file.remove();
file.open();
file.write(Json.encode(data));
file.close();
After executing this, you can examine the file 'data.json' that you will find in the same directory as the script, due to the script.file.parent that was passed as the parent to the File constructor. You will find this JSON describing your data: [false,1,2,3,"four",{"five":6}].
Now in order to read that back, you can do:
var file = new File(script.file.parent, 'file.json');
file.open();
var data = Json.decode(file.readAll());
file.close();
print(data);
And this will print: false,1,2,3,four,[object Object]. Note that toString() does not describe the contents of objects, whereas Json.encode() does.
I hope this helps?