How are scripts from commandline executed
The script is currently executed after rendering. The order of CLI command matters for Blender. If you put the --python flag before -f it should work as expected.