One question is do these verses state that the people were destined to sin when they would come into the land of Israel? Note, this same question would seem to apply to 30:16, 29; also 4:25. If the answer is yes, then the people have no free will. However, Moshe seems to affirm the principle of free will at the end of his speech by the establishment of the covenant on the plains of Moav, 30:15,19. Yet, if people have free will, then how could G-d state the people were destined to worship other gods? Thus, either one must understand these verses as being conditional that if the people would sin, which seems difficult, or that in these verses G-d was saying that there was a high probability, but not 100%, that the people would sin. Note, as one refers to more and more generations of people, then the cumulative odds would get higher and higher that some generation would sin.
A second related question is do these verses imply that G-d does not know the future? 31:21 states that G-d knew the people would sin since He knew their yetser, but if He knows the future, then there is no reason to relate G-d’s knowledge of the future to the people’s yetser in the present. Ibn Ezra (on 31:21) writes that the verse means that even if G-d did not know the future, still G-d would have known that the people were going to sin. My impression is that the Torah (see Bereshit 6:6) is written based on the idea that G-d does not know the future, and hence 31:20,21 should be understood that since G-d knew that people are selfish, He could predict with a very high certainty that the people would worship idolatry in the future. One might wonder how being selfish would lead a person to worship other gods, but it could be that people would worship other gods in order to get the “benefits” they would think come from worshipping these other gods, that the person would think that he/ she is “covering his/ her bases.” With regard to the basic question of does Judaism believe that G-d knows the future, this might depend on how one understands Pirkei Avot 3:19.
A third unrelated question is if there was a high probability that the people would sin when they would come into the land of Israel, why would G-d give the people the land of Israel? One answer could be there was still a small chance the people would not sin. A second answer is that they received the land of Israel based on their present status, and while they had the yetser even before they entered the land of Israel, it had not yet caused them to sin. A third answer is that they received the land since G-d had promised it to the patriarchs, which is re-called in 31:20.
The connection between these verses and the flood is that the word yetser only occurs three times in the Torah, here, before the flood, Bereshit 6:5, and after the flood, Bereshit 8:21. Alter (2004, p. 1035) writes, "This relatively unusual word, yetser, is surely a pointed allusion directing us to G-d's bleak words about human nature after the Flood: For the yetser of the human heart is evil from youth." This word establishes a connection between the beginning of the Torah and the end, but what is the connection?
Why did G-d re-start the world after the flood if people have this yetser which can cause them to be evil? Maybe, the entire Torah is to answer the question can people be good even though people have this yetser? If the answer is a categorical no, then there was no point to re-starting the world after the flood. However, G-d did re-start the world after the flood, which means that even though people have this yetser, this selfishness, a (the) point of the Torah was to teach man to overcome/ modify or channel his yetser to become a good person.
When it is all said and done at the end of the Torah, does G-d think that people will succeed or not in overcoming/ modifying or channeling their yetser to do good? The answer from 30:20,21 is not a resounding yes, as otherwise G-d would not have stated that the people were going to sin in the future. However, since we have argued that the verses are speaking in probable terms, even highly probable that the people will sin, still there is some chance that people will not sin. Some people at some time, will be able overcome/ modify or channel their yetser and be good people, but others, maybe the majority, will fail. This possibility leaves people with the free will to be good or bad even though we have this yetser.
Alter, Robert, 2004, The five books of Moses: A translation and commentary, New York: W. W. Norton and Company