If you're talking about a web browser, the character set the browser uses to interpret the file is determined by the Content-Type
header sent with the file by the server. (script
tags also have a charset
attribute, but if the server says something different, the server wins. Best to ensure the server is sending the right information.)
So the file must be written to storage using the character set that the server will tell the browser it's using. It's a fairly common error to store the file as Windows-1252 or ISO-8859-1, but have the server send it saying it's UTF-8, which causes the kind of issue you've raised.
Ensure that the encoding of the file and the encoding the server reports match, and characters won't get messed up.
Obligatory link to an article by one of the SO founders, Joel Spolsky: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).