allow overriding sys.stderr before calling print_error

Scanner.print_line_with_pointer captures sys.stderr at definition time, meaning if it's changed later it'll still use the old one; fix that by looking for sys.stderr at each call.
Additionally, fixed stray print statements that lead to TypeError because the file imports print_function.