(I made an edit, read it first)
I don't think it's idiomatic, at least not the whole expression.
"Être connu" means "to be famous/well known" , and "gagner à [qq chose]" means "to benefit from [something]".
You can say "gagner à" with anything (same for "être connu"), even though it's a little formal.
You can't say "Je savais bien qu’on gagnais à me connaître". "Je suis connu" and "*on me connaît" are not equivalent, when "connu" means "famous", it's used as an adjective. For the same reason, "je suis perdu" and "on me perd" do not mean the same thing at all.
(btw I'd like to have context for this sentence if you have it, I can't really translate right know. Are you talking about selling a book or being known by your colleagues ?)
EDIT : According to these sources from the Wiktionary (Gagner (see 17), gagner à être connu) the expression seems to 1. be idiomatic and specific to the pair "gagner à" and "connu" 2. means "to deserve to be better known".
However, note that:
- the page about "gagner" doesn't explicitly say it should be used only with "connu"
- it's colloquial (familier)
- it's not an absolute truth, and the specific part about that expression are kind of poor in content. I wouldn't see them as completely reliable, but it should be better than my general feeling about what I think I know about that expression.
Still, I've only seen it used for places, like restaurants, independant movie theaters, or for an author, a novel, a series, etc. I wouldn't use it for people, in a way unrelated to fame.
The part about the inversion still holds, I wouldn't say "Je savais qu’on gagnais à me connaître (mieux)." (at least, not meaning "deserve")