Fix stdout closing/reopening around save().

The save() callback prints rules to stdout in the extension. Make sure
we close and then reopen not just the low-level fd, but the Python file
as well around it.