Pass nbformat object to write call to save .py script

Closes #4495