Linoxide published a tutorial about how to use Sudo when using with redirect or pipe.
How to Use Sudo when Using with Redirect or Pipe
Using sudo with redirection (>) or pipe (|), bash output with permission denied error message, show you different ways to fix that problem.
How to Use Sudo when Using with Redirect or Pipe