To summarize my (prior) comments on the issue here, this is seemingly more feasible for the state legislature of Ohio.
Ohio's constitution allows swapping the deceased with another representative from the same party, with no broad-based election, but a vote on the floor of the legislature. And on closer reading, it's only the members of the (state) House caucus of the party of the deceased that actually vote on that matter, so it's like a floor primary of sorts for the Ohio state legislature vacancies. Maybe West Wing applied some poetic license and used/assumed that procedure for federal vacancies...
A vacancy in the Senate or in the House of Representatives for any cause, including the failure of a member-elect to qualify for office, shall be filled by election by the members of the Senate or the members of the House of Representatives, as the case may be, who are affiliated with the same political party as the person last elected by the electors to the seat which has become vacant. [...] An election to fill a vacancy shall be accomplished, notwithstanding the provisions of section 27, Article II of this constitution, by the adoption of a resolution, while the Senate or the House of Representatives, as the case may be, is in session, with the taking of the yeas and nays of the members of the Senate or the House of Representatives, as the case may be, affiliated with the same political party as the person last elected to the seat in which the vacancy occurs. The adoption of such resolution shall require the affirmative vote of a majority of the members elected to the Senate or the House of Representatives, as the case may be, entitled to vote thereon. Such vote shall be spread upon the journal of the Senate or the House of Representatives, as the case may be, and certified to the secretary of state by the clerk thereof. The secretary of state shall, upon receipt of such certification, issue a certificate of election to the person so elected and upon presentation of such certificate to the Senate or the House of Representatives, as the case may be, the person so elected shall take the oath of office and become a member of the Senate or the House of Representatives, as the case may be, for the term for which he was so elected.
One interesting aspect of that process is that the replacement thus elected (by the party floor caucus) receives a certificate from the secretary of state seemingly in exactly same way as if elected by a broad-based election.
One has to wonder if this is not possible for federal elections as well, since the US constitution only says (Art I, sec 2) that a writ of election needs to be sent...
When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies.
But if the secretary of state says an election happened (even if it was just in some partisan caucus)... here's the certificate... what then?
As far as the US HoR though, I think that would not fly because there is precedent since the 1960s for the HoR to override state laws and ever do their own recounts (in rare cases) when they considered the state election rules problematic. (The HoR rejected the state-certified result in at least two cases, and seated the opposing candidate.) I'm almost certain that would happen if a state decided to run such an replacement election in a partisan (or otherwise narrow) caucus.
This (refusal to seat) is constitutional because
based on Article I, Section 5 of the United States Constitution which states that, "Each House shall be the judge of the elections, returns and qualifications of its own members, [...]
The Supreme Court has limited the HoR's ability to refuse to seat in some circumstances, but those limitations are predicated by someone being "duly elected" in the first place.