I think that's a really interesting idea and not at all overpowered, primarily because of the lack of control you have over what it discards. I mean, you can control it by what you choose to put in your deck, but if it takes work and/or specific circumstances to unlock a powerful feature of a card, that's okay. Menagerie is an example of just such a card. A double-Laboratory for $3 is way better than what this card can do for you, which is a Cartographer, tops.
You should specify what you do with the undiscarded cards, though. "Put the rest back on top in any order" would be the usual verbiage. The "any order" part isn't strictly necessarily, but it's in keeping with the spirit of Dominion. Donald specifically designed such cards with "put back in any order" clauses so players wouldn't have to keep track of what order the cards came off the deck in.
I like that, in the right deck, it basically filters out Coppers, Estates, and Curses for free (minus the opportunity cost of buying one, of course). But it does take the right deck. You don't want it in a Hunting Party, Minion, or Conspirator stack, for example, or a Torturer chain. That's why I think it's okay at $3. It takes a niche and even then will be uncertain. But yeah, with Cornucopia cards or Black Market, it could be terrific.
Playtesting might show that a different number of cards might be an improvement. I could imagine you might want to look at 6 cards rather than 5, although 5 seems like the right place to start.