The anti-gay stuff was a minor issue for McCarthy, but actually took off to a greater extent than worries about communist infiltration of the government did in some ways, including among many people (like Margaret Chase Smith) who were strongly critical of McCarthy's claims about communist infiltration. There was a surprisingly wide consensus that homosexuals were "security risks" who needed to be rooted out of the government lest they be blackmailed into revealing national secrets. McCarthy himself seems to have been surprised by, and perhaps even uneasy with, the sudden national obsession with getting homosexuals out of the government, although he had partly started it. See David K. Johnson's Lavender Scare for more on this.
"What was really driving McCarthy" is a hard question. While there was certainly actual communist infiltration of the government, McCarthy made a lot of unsupported claims, and I think there has to have been some degree of deliberate charlatanism on his part. McCarthy's political career was in a difficult spot before he started waving around his lists of alleged communists, but he soon became one of the most influential and popular politicians in Washington.