Standing on the shoulder of giants I often tweak someone elses code to suit my needs. If I use io.open and os.date in any rombot related script it works fine but if I use them in code that used in interface\addons such as PetAutoEvent the code just doesn't get executed. I've put chat window messages before and after the code and it's like the script aborts at that point. I use exactly the same code in both cases.....
Yes unfortunately there is nothing wrong with the code, it is the game itself that has the issue.
Over the years they have removed functions you would normally have in LUA.
Even something as simple as os.time() won't work, there is an addon called d303fix which added back in a function for using os.time() by getting the time from items in itemshop with a timer for when it is available.
So long story short not all functions work in addons for RoM.
Remember no matter you do in life to always have a little fun while you are at it