scripts: Add try/catch block to freeeze when writing data to file