But when i write the above coding by inserting a line between the print statement and the content type as shown
i get the file printed directly in the browser, not in the excel format. I don't know the reason for that. So Monks your valuable thoughts in the above. Thanks.

It's hard to see what you're saying as your question is formatted so badly that the whitespace that you are talking about disappears. Please use <code> tags round your code examples.

Your problem is that the blank line you are introducing is taken as ending the CGI headers. Therefore your header is seens as being part of the body of the response and the web server adds its own default content-type header (probably saying that the content is text/html). You can't have that blank line there as the first blank line in the response defines the end of the header.

Update: Now that Corion has added code tags I can see what you're doing a little more clearly. I'm not sure why it's working as it is, as you need you insert a blank line between the end of the headers and the start of the content.

That's because the HTTP headers end with the first blank line. If you start with a blank line, the server says "oh, that's the end of the headers: I'm going to assume this is just text, then". When the browser is told "this is text", it just displays it.

This is sort of like the old doctor joke: "Doctor, it hurts when I do this!" -- stop doing that. ;-)

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other