This question was previously closed as a duplicate of
this question, which asserts that if $f : X \to Y$ is a homeomorphism and that if $C$ is a connected component of $X$, then $f(C)$ is a connected component of $Y$, and $C$ is homeomorphic to $f(C)$. Per that linked question, if $f : (0,1)\cup (1,2) \to \{a,b\}$, then it must be that either $f((0,1)) = \{a\}$, or $f((0,1)) = \{b\}$. In either case, the restriction of $f$ to $(0,1)$ is a homeomorphism from an uncountable set to a singleton. By a cardinality argument, this can't happen. —
Xander Henderson ♦ 2 mins ago