Tangentially related, but when I switched my cat from commercial cat food to a raw chicken (w/ supplements) diet, her poops went from very bulky once a day, to shrivelled poops every-other day.
The amount of water in the chicken, and the lack of bulking ingredients made a huge difference.
You are describing pickle, but it does come with some serious risks, especially if the file can be modified by a third party.
https://arjancodes.com/blog/python-pickle-module-security-risks-and-safer-alternatives/
I’d suggest using protobuf or similar instead, but its a bit more work.