Pass nbformat object to write call to save .py script

Closes gh-4495