A try like the following command failed
$ sudo echo "echo hello" > /usr/local/bin/hello
with an message
bash: /usr/local/bin/hello: Permission denied
It seems the writing to the file is executed under the non-root user.
You can make sudo invoke bash which executes your command:
sudo bash -c 'echo "echo hello" > /usr/local/bin/hello'
Another way is to use
tee to write to file instead of STDOUT redirection:
sudo echo "echo helo" | sudo tee /usr/local/bin/hello >/dev/null