works just fine for removing the ^M from flange.txt, I could not spot in your code where you were trying to do the ^M translation. As to how to how to imporove it generally. I will get back to ya on monday, sorry but it is my home time now.
HTH (a bit)
--