sudo has not been usable or appropriate with Homebrew on macOS for a few years now. The INSTALL.sh should not be sudo sudo, or should use sudo to escalate only when not running homebrew. See the Homebrew FAQ:
Why does Homebrew say sudo is bad?
tl;dr Sudo is dangerous, and you installed TextMate.app without sudo anyway.
Homebrew refuses to work using sudo.
You should only ever sudo a tool you trust. Of course, you can trust Homebrew 😉 But do you trust the multi-megabyte Makefile that Homebrew runs? Developers often understand C++ far better than they understand make syntax. It’s too high a risk to sudo such stuff. It could modify (or upload) any files on your system. And indeed, we’ve seen some build scripts try to modify /usr even when the prefix was specified as something else entirely.
We use the macOS sandbox to stop this but this doesn’t work when run as the root user (which also has read and write access to almost everything on the system).
Did you chown root /Applications/TextMate.app? Probably not. So is it that important to chown root wget?
If you need to run Homebrew in a multi-user environment, consider creating a separate user account especially for use of Homebrew.
sudo has not been usable or appropriate with Homebrew on macOS for a few years now. The INSTALL.sh should not be sudo sudo, or should use sudo to escalate only when not running homebrew. See the Homebrew FAQ: