The consequence is that your new position may be unfavorable
As far as I know, there are no direct consequences for walking right into a hidden enemy in this way, even if that enemy can see you. That is, the enemy doesn't get an automatic opportunity attack or something like that. The main consequence of walking into an enemy is that you are now in that enemy's melee range. This, of course, has all the usual consequences of getting into melee, such as giving you disadvantage on ranged attacks and putting you in danger of provoking an opportunity attack if you move back out of melee.
Obviously, if your original plan was to make a ranged attack against your enemy, then you probably don't want to put yourself in melee with them just to uncover their location, so using this strategy would be a bad idea. If you're wielding a melee weapon and you're just trying to make sure you don't swing at empty air, using your movement to discover an enemy's exact location seems like a reasonable plan.
If the enemy can see, you risk an opportunity attack
While running directly into an enemy doesn't provoke an opportunity attack, running past them without running into them does, as long as the enemy can see you:
You can make an opportunity attack when a hostile creature that you can see moves out of your reach.
The problem is, the whole reason you're doing this maneuver is because you don't know exactly where your enemy is. So you don't know if you're going to run into them or past them. This means that if your enemy can see, you are indeed risking an opportunity attack by blundering about in the dark searching for them. Looking on the bright side, you'll definitely know where the enemy is after they take a swipe at you (at advantage, since you can't see them).
This isn't guaranteed to find an intelligent enemy who wants to stay hidden
It's also worth noting that if the enemy has already taken the Hide action and their goal is simply to remain hidden rather than attack you, they can do so by readying a move to walk out of your way as you walk past them. If they do this, then you could move through every space where they could possibly be hiding and still fail to run into them.