refactored http WriteToFile