bpo-34108: Fix double carriage return in 2to3 on Windows (GH-8271) (#8275)

* Add test capturing failure.
* Honor newlines as present in the original file.
(cherry picked from commit cafaf0447b950fd4f59edd8cbde040c61ae528f8)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 7c4e064..7841b99 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -514,7 +514,7 @@
         set.
         """
         try:
-            fp = io.open(filename, "w", encoding=encoding)
+            fp = io.open(filename, "w", encoding=encoding, newline='')
         except OSError as err:
             self.log_error("Can't create %s: %s", filename, err)
             return