I would not remove the tmp files, unless you reboot after the script execution.
Even orphaned packages might be there for a reason and should not be removed.
The only thing I do when disk space get's low, is to remove the cache folder, if the systems is stable.
But building this scripts and others, it is always a great experience. We all did this.
Always read the wiki https://wiki.archlinux.org/title/System_maintenance
roscas•3h ago