First: My English is Bad (I'm using Big Sur)
After install Homebrew, try command: brew doctor on terminal.
This command show how you install de XCODE software to execute the terminal commands.
You can try other way on homebrew website on "homebrew documentatio installation xcode3"
After install XCODE, repeat the homebrew installation, repeat a command "brew install upx".
After install UPX, use the command "sudo..." for unpack the file.
Enjoy.
Sorry for my english.
Hope this helps.