The most common publish error is to specify an incorrect filepath to read/write data files. Since the unpacked script runs from a temporary directory, filepaths are relative to this location and not the EXE file.
If a data file is read only and there's no reason to modify the file from one run to the next it can be saved inside the EXE. In this case both the running script and the data file are unpacked to the same directory. You can specify a relative path to open the file:
For read/write access to a file outside of the EXE you'll want to use an absolute path or path relative to the EXE. Use the viz.res.getPublishedPath() command to get the EXE filepath. Add the code below to your script from the last section. This opens and writes data to a file in the same directory as the EXE:
Publish the script and run the EXE. You should see the data.txt file saved in the EXE directory.