Whenever you apply task progress to any task assignment by applying timephased Actual Work, Microsoft Project will always change the Work Contour from Flat to Contoured. This is true whether timephased Actual Work is entered manually or by using a programmatic approach such as you are using. There is no way to stop Microsoft Project from doing this, as this is the default behavior of the tool.
What I do not understand from your post is the second half of the question with regards to leveling resource overallocations. Could you please explain further, and maybe even include a screenshot so we can see what is happening? Please let us know and we will try to help you. Thanks!