less-hacky way of running sudo command and redirecting output (works with immediate write for long-running commands too)