With a cursory examination, it looks like the OP's proof is in the ballpark. They asked for a proof that would be more efficient, so here we will highlight the main ideas found in the OP's proof, presented as a logical progression.
In what follows we do not assume that our sets are contained in $\mathbb R$.
Proposition 1: If $A_1$ and $A_2$ are two disjoint countably infinite sets, then the union $A_1 \cup A_2$ is countably infinite.
Proof:
Let $F_1: \mathbb N \to A_1$ and $F_2: \mathbb N \to A_2$ be bijective mappings, where $\mathbb N = \{0, 1, 2, \dots, n, \dots \}$. Define $F: \mathbb N \to A_1 \cup A_2$ as follows:
$$
F(m) = \left\{\begin{array}{lr}
F_1(\frac{m}{2}), & \text{for even } m \in \mathbb N\\
F_2(\frac{m+1}{2}-1), & \text{for odd } m \in \mathbb N
\end{array}\right\}
$$
It is easy to check that $F$ describes a bijective correspondence. $\quad \blacksquare$
The following sequence of 'add-on' propositions are not difficult to prove:
Proposition 2: Let $A_1$ and $A_2$ be any two sets. Then there exist a set $B$ satisfying the following:
$\tag 1 B \subset A_1 \text{ and } B \subset A_2$
$\tag 2 A_1 \cup A_2 \text{ is the disjoint union } (A_1 \backslash B) \cup B \cup (A_2 \backslash B)$
Proposition 3: If $A_1$ is a countably infinite set and $A_2$ is any finite set, then the union $A_1 \cup A_2$ is countably infinite..
Proposition 4: Any subset of a countably infinite set is either finite or countably infinite.
Proof (sketch)
Use the lemma found here.
Proposition 5: The union of a finite number of finite sets is finite.
We now prove the main proposition.
Proposition 6: The union of any two countably infinite sets $A_1$ and $A_2$ is countably infinite.
Proof:
By proposition 2, 4 & 5, $A_1 \cup A_2$ can be written as a disjoint union
$\tag 3 C_1 \cup B \cup C_2$
where each of the sets is either countably infinite or finite, and at least one of the sets is countably infinite.
By using the commutativity and associativity laws of the union operation and proposition 1 and/or proposition 3, we can simplify (3) in two steps so that a single countably infinite set remains that is equal to $A_1 \cup A_2$. $\quad \blacksquare$
The OP might want answer this question again at some point using the following:
Theorem: If $f$ is a surjective function from $\mathbb N$ onto a set $A$, then $A$ is either finite or countably infinite.
An approach like yours can be made to work, but there is a completely different approach that is easier, if perhaps less natural.
Define a relation $\sim$ on $S$ as follows: for any $x,y\in S$,
$$x\sim y\text{ iff }[\min\{x,y\},\max\{x,y\}]\subseteq S\;,$$
i.e., $x\sim y$ if and only if the closed interval between $x$ and $y$ is contained in $S$. It’s not hard to show that $\sim$ is an equivalence relation on $S$. Let $\mathscr{C}$ be the set of $\sim$-equivalence classes; the members of $\mathscr{C}$ are certainly pairwise disjoint subsets of $S$ whose union is $S$, so we’ll be done if we can show that they are canonical sets and that $\mathscr{C}$ is finite.
Let $C\in\mathscr{C}$. $S$ is a bounded set, so $C$ is bounded, and we can let $a=\inf C$ and $b=\sup C$; now we need only show that $C=[a,b)$. Certainly $C\subseteq[a,b]$; I’ll show next that $(a,b)\subseteq C$. Suppose that $x\in(a,b)$; then $a<x$, so there is a $c_0\in C$ such that $a\le c_0<x$. Similarly, $x<b$, so there is a $c_1\in C$ such that $x<c_1\le b$. Then $c_0\sim c_1$, so $[c_0,c_1]\subseteq S$, and since $c_0<x$, it’s clear that $[c_0,x]\subseteq S$ as well. But then $x\sim c_0\in C$, so $x\in C$, and since $x\in(a,b)$ was arbitrary, it follows that $(a,b)\subseteq C$. Now we must show that $a\in C$ and $b\notin C$.
Suppose that $b\in C$. Then $b\in S$, so there is an $i\in\{1,\ldots,n\}$ such that $b\in I_i=[a_i,b_i)$. Then $b<b_i$, so choose any $x\in(b,b_i)$; $x\in S$, and $[b,x]\subseteq I_i\subseteq S$, so $b\sim x$, and therefore $x\in C$, contradicting the definition of $b$ as $\sup C$. This shows that $b\notin C$.
Now suppose that $a\notin C$; $a=\inf C$, so there is a strictly decreasing sequence $\langle x_k:k\in\Bbb Z^+\rangle$ in $C$ converging to $a$. Each of the points $x_k$ belongs to one of the sets $I_i$ with $i\in\{1,\ldots,n\}$, and there are only finitely many of these sets $I_i$, so there must be some $i\in\{1,\ldots,n\}$ such that $A=\{k\in\Bbb Z^+:x_k\in I_i\}$ is infinite. Now $\{x_k:k\in A\}\subseteq[a_i,b_i)$, so
$$a_i=\inf[a_i,b_i)\le\inf\{x_k:k\in A\}=a\;.$$
Pick any $k\in A$; then $[a,x_k]\subseteq[a_i,x_k]\subseteq S$, so $a\sim x_k\in C$, and therefore $a\in C$. This completes the proof that $C=[a,b)$ and hence that the partition of $S$ into $\sim$-equivalence classes is a partition of $S$ into canonical intervals.
Finally, it’s easy to check that for each $C\in\mathscr{C}$ there is an $i(C)\in\{1,\ldots,n\}$ such that $I_i\subseteq C$ and that the map $\mathscr{C}\to\{1,\ldots,n\}:C\mapsto i(C)$ is injective, so that $|\mathscr{C}|\le n$.
Best Answer
If the sets $X_i$ are compact, you will be in good shape. 0XLR gave a counterexample in $\mathbb R$ where one of the sets was not closed. Here is a counterexample where the sets are not bounded.
Let $$ X_1 = \{1,2,3,\dots\}, \\ X_2 = \left\{1+\frac{1}{1}, 2+\frac{1}{2}, 3+\frac{1}{3}, \dots\right\} $$ Set $f(x) = 0$ on $X_1$ and $f(x) = 1$ on $X_2$. Then $f$ is uniformly continuous on $X_1$ and on $X_2$, but not on $X_1 \cup X_2$.