Israel endured many discomforts during those forty years, and they sinned a great deal too. However, God reminds them that He was with them during both good and bad times. He also makes it very clear that He Himself inflicted a great deal of pain on them, and that He did this for three specific reasons: to humble them, to know what was in their hearts, and to teach them that man does not live by bread alone.
If He did these things to humble them, then the flip side is that He did it to knock the pride from them. Pride motivated many of their sins. As a recurring theme in Scripture, God's work to humble us is something to keep at the forefront of our minds. The author of Hebrews warns us, "Do not despise the chastening of the Lord" (Hebrews 12:5). He is deeply involved in our lives, and because He loves us dearly, He will correct us painfully when necessary (verse 6).
Deuteronomy 8 teaches that God humbles us to drive the pride of self-sufficiency far from us. When things go well, it is easy to forget God and ascribe success to natural abilities, learned skills, or even good luck. But when the body is not fed, it begins to weaken noticeably, and it soon begins to feel pain. The spirit, though, seems to weaken and "die" so slowly that it is almost imperceptible. As we spiritually deteriorate, we may even feel blessed and prospered by God! So He disciplines us with pain to warn us that all is not as well as our vanity is leading us to think.