You should never be setting DOCTYPE or <html><head><body> tags. These go once on each html page *and have already been sent* by MediaWiki. You only write content html tags.