Understanding it needed to do that is a bit of personification. The Venus fly trap that grew a slightly taller flower stem got pollinated more. That genetic mutation overtook the species as competition for pollination grew more difficult for the shorter flower stemmed. Evolution is cool an all, but let’s not confuse it for plants knowing or deciding to do anything.
An old fashioned meme but it checks out