Before jumping to the solution, I think it is important to address your question about what is causing the problem. There are several possible causes:
1) You do not have a form called "UserProfile" in the database design, and the "MasterProfile" form is the default form in the database. If that's the case, then every time you open the document in the Notes UI you are loading the MasterProfile form as the default. So when you save the document, the value in the Form field is going to change to the loaded form name, which is "MasterProfile".
2) You do have a "UserProfile" form in the database, but it has an alias that is set to "MasterProfile". When you save a document in the Notes UI, the Form item will actually be set from the alias name of the form, not the primary name, so this would cause the Form field to change to "MasterProfile".
3) You do have a "UserProfile" form in the database, but you have a computed field called "Form" on the form, and the formula for that field is actually "MasterProfile". When you save a document in the Notes UI, the computed value of the Form field will override the name and alias of the loaded form, so this would cause the Form field to change to "MasterProfile".
4) Your application is using a rarely-used feature of Notes called a "Form Formula". I.e., the design of the view that you are opening the documents from has a Form Formula whose value is "MasterProfile". A Form formula in a view causes the UI to use the formula result to override the Form field that is stored in the document. A nasty side-effect of using Form Formulas is that when you save the document, the value in the Form field is going to be canged to the overridden name, which is "MasterProfile".
There are actually several other possibilities, but I think they are less likely than any of the above.
The solution to #1 is to create a subform called "ProfileSubform" and copy the entire contents (fields and event scripts) of the "MasterProfile" for to it. Then wipe the MasterProfile form completely clean and insert the new subform into it. Then create a "UserProfile" form and insert the MasterProfile form into that, too. (Ken Pepisa's suggestions are also good, however the virtue of what I am suggesting is that you can do it without making any other changes to your application.)
The solution to #2 is to get rid of or correct the alias of the "UserProfile" form.
The solution to #3 is to get rid of or correct the Form field on the "UserProfile" form.
The solution to #4 is more problematic. If you can get rid of the Form formula in the view, then do it... but it might be there for a reason. You may have to make it smarter, and/or you may have to go with one of Ken's suggestions.