The following command does not work because the elevated privileges do not apply to the redirection.
sudo echo "myoutput" >> /etc/file_that_only_root_can_write
how can it be done?
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.