Based on the markup in that file, it looks like you probably saved the file as an HTML document from TextEdit.
TextEdit is not a particularly good HTML editor. (I suppose it’s usable if nothing else is available, but it’s still not ideal.) I’d strongly recommend that you pick up something like Sublime Text or TextWrangler; they’re both very good code editors which will make it much easier for you to work with HTML.
If you must use TextEdit, though, make sure that the document is set up as a plain text document before you save it. (That is, there should be no “formatting ribbon” at the top of the window containing options like font and size.) You can switch a document between plain text and rich text using the “Format > Make Rich Text / Make Plain Text” menu item.