REMOVE THE WORD 'ATTACHMENT'
I don't know why someone gave you the advice to change the content-disposition header to attachment type. THIS IS NOT AN ATTACHMENT.
Make sure the header line is:
PHP Code:
header("Content-disposition: filename=messages.txt");
header("Content-type: unknon/unknown");
header("Pragma: no-cache");
header("Expires: 0");
And you will be prompted to save messages.txt (or whatever filename you gave).