Thank you for sharing the script and it's always nice to see people leveraging our APIs 😀
I wanted to ask though, why you don't perform this action through the SmartConsole UI? (or perhaps the option is not visible enough...).
If you open the Object Explorer (via the top menu or by clicking the three-dots in the right side Objects pane), there is a combobox at the top left that says "All" by default. If you open it, you can select "Unused Objects" instead and it will filter the contents. You also have the left side filters to hierarchically filter by object types.
Once you filtered for what you wanted, you can multi-select all objects and delete them.
Also, another comment that can help you make the script more efficient is to leverage the "delete objects-batch" command that can delete many objects in a single API call and transaction:
https://sc1.checkpoint.com/documents/latest/APIs/index.html#cli/delete-objects-batch~v1.9.1%20