> when I try
sudo echo napalm >> /opt/netbox/local_requirements.txt I get permission denied.
You will indeed get an error if you do that. That's because the shell first tries to connect stdout to /opt/netbox/local_requirements.txt (as the current user), *before* running the command "sudo echo napalm". However the current user doesn't have rights to open that file for write/append.
Solution 1: switch to a root shell first, before doing the redirection
sudo -s
echo napalm >>/opt/netbox/local_requirements.txt
exit
Solution 2: use "tee -a" to append to the file; this works because it doesn't open the file until after it's started. (You'll see this used often in snippets on the web, as it's a convenient one-liner)
echo napalm | sudo tee -a /opt/netbox/local_requirements.txt
Solution 3: get a root subshell to do the redirection (converting solution 1 to a one-liner)
sudo bash -c "echo napalm >>/opt/netbox/local_requirements.txt"