It has permission via certificates and writes/copies either via bin commands (cp) or the user does it (drag app to applications). Applications don’t own files within macOS. It’s UNIX methodology where it’s a user/group/everyone situation. Often files will be owned by “system” or the logged in user that installs them. The OS would need to snapshot what is done during installation (which is actually done by packaging utilities like composer) but this is also prone to error because it tracks all changes during installation, so if you’re modifying files with other apps while the current installer is running in the background it will capture that. And I think you’d be surprised how many apps keep files in non-traditional places.
It’s just not as straight-forward as you think it is and no OS really does this will. Windows uninstaller often misses a lot of registry keys and programdata/appdata files. Linux will only uninstall what it install during the apt/dnf/whatever process. Even iOS leaves things behind like folders in Files.
Not great timing with UPS about to go on strike. I personally nearly always order online and then set to pick up in store since UPS is an absolute shitshow in my area.