You say you can create the file successfully. When you open the file with notepad, what do you see ? (Post a screen shot).
This message is generally the message that Excel outputs when some one creates an Ascii Tab delimited file with an XLS (or XLSX) extention.
Excel complains because the file is NOT an Excel file. It is a file that can be read by Excel, a subtle difference.
Rich