You will have to use the NW.js plugin for this, if you want to write dynamically to a text file.
With NW.js, you can use the action "Append file" to add a new line to the file, every time something happens.
If you don't want to export to NW.js, you can use a dictionary or Array and use the Browser action "Download String" to download the Dictionary or Array as JSON.