You give your function a new_doc argument, which you do nothing to, and then you save it using document.save(new_doc). Do you not need to apply some changes to the new_doc?
new_doc
document.save(new_doc)