The error is because you are only allowed to write to the world folder (minetest.get_worldpath()
). There's also a syntax error in the code snippet - 
indicates that something is optional - io.open(filename, "w")
will open a handle.
You should avoid reading and writing to files manually in minetest. It tends to be inconvenient and subject to data loss (if you don't write safely)
Instead, you should prefer using meta data such as Mod Storage
Code: Select all
-- Call this in init.lua
local storage = minetest.get_mod_storage()
-- Some other function
storage:get_string("foo") --> "bar"