Cleaned file saving

* Shared logic moved to a function
* Saving the binary protobuf didn't work if the name contained /
Changed shebang to work with virtualenv paths and made file executable