but rather than using game.write_file, I'd suggest an intermediary broker service that wraps factorio's rcon interface and do message passing with json or vOn, setup a message handler/dispatcher using rcon.print and the ability to execute commands via rcon
I did something similar a while back for a custom factorio server where one team on factorio would build the units that another team deployed in OpenRA, which would then return the tiberium back to the factorio world to convert to resources.
does mean any factorio game would need to be multiplayer, unless the devs add rcon support for singleplayer outside the inbuilt console.