Recent versions of macOS restrict access to system areas of the file system.
I'm not certain of the preferred location these days since most searches seem to only result in XCode Command Line Tools, but looking at the Homebrew information it appears "/usr/local" may be the correct folder for Intel Macs while "/opt" is for M1/M2 Macs with Apple Silicon (at least that is what Homebrew is using). From the Homebrew documentation, they give the following reason for using "/opt" on an M1/M2 Mac with Apple Silicon:
https://docs.brew.sh/FAQ
Why is the default installation prefix /opt/homebrew on Apple Silicon?
The prefix /opt/homebrew was chosen to allow installations in /opt/homebrew for Apple Silicon and /usr/local for Rosetta 2 to coexist and use bottles.
For reference to the system area restrictions, check out these two Apple articles:
About the read-only system volume in macOS Catalina or later - Apple Support
Signed system volume security in iOS, iPadOS, and macOS - Apple Support
Hopefully another more knowledgeable contributor will be able to provide a better answer or confirm my information is Ok.