added file write function
fix for windows and proper filetype choosing