When I download a text file, .txt gets added to filename. How do I prevent this? When I download a text file with extension .mac (or any extension but .txt) the file downloads but the extension .txt is added to file name. How do I prevent this from happening?
You can only in general prevent this if you control the server. 

I assume you're talking about downloading using a browser - in which case the web server controls the file type and naming using the Content-Type MIME indication as well as the Content-Disposition header for specifying the file name.