Example 2 Given the set $X=\{1,2, \cdots, k\}$, for $A \subseteq X$, denote the sum of all elements in $A$ as $S(A)$. Divide $X$ into two disjoint subsets $A, B$, and $A \cup B=X$. If $S(A)=2 S(B)$, find all values of $k$.

---

The translation maintains the original format and line breaks as requested.
Given $A \cup B=X, A \cap B=\varnothing$, and $S(A)=2 S(B)$, hence $S(X)=3 S(A)=\frac{k(k+1)}{2}$ is a multiple of 3.
That is, $3 \mid k$ or $3 \mid(k+1)$.
(1) When $k=3 m$, let $A=\{1,3,4,6, \cdots, 3 m-2,3 m\}, B=\{2,5, \cdots, 3 m-1\}$, then $A, B$ satisfy the requirements.
(2) When $k=3 m-1$, let $A=\{2,3,5,6,8, \cdots, 3 m-3,3 m-1\}, B=\{1,4,7, \cdots, 3 m-2\}$, then $A, B$ satisfy the requirements.
Therefore, $k=3 m$ or $k=3 m-1(m=1,2, \cdots)$.