Modifying the user agent via the headers will indeed change the UA string that the server sees.
However, it doesn't mean that you're actually changing the User agent string that the browser knows about.
You're querying the UA string via javascript; that will be getting the actual UA string in the browser; nothing to do with the headers that have been sent to the server.
If you want to override the UA string properly, there are firefox extensions that specialise in doing so. I suggest you use one of them, rather than a generic header override extension.