tl; dr Yes, this is true. Intuitively, if $\ell$ is not a line, there exist three non-collinear points on $\ell$, which is incompatible with $\ell$ being the image of an isometry.
$\newcommand{\Reals}{\mathbf{R}}$One (standard) proof is to let $\ell$ be an arbitrary line, and to fix a distance-preserving bijection $f:\Reals \to \ell$. Pick distinct points $p$ and $q$ of $\ell$ arbitrarily, and let $L$ denote the Euclidean line through $p$ and $q$. Finally, let $v$ be the unit vector parallel to the displacement $q - p$, and let $n$ be either of the two unit vectors orthogonal to $v$. (This is where we're using the Euclidean metric and its origins with an inner product.)
It suffices to show the image of $f$ is contained in $L$.
By hypothesis, there exist real numbers $a$ and $b$ such that $p = f(a)$ and $q = f(b)$. By exchanging the names of $p$ and $q$ if necessary, we may assume $a < b$ without loss of generality. The isometry condition on $f$ implies $t_{0} - a = d_{E}(p, f(t_{0}))$ and $b - t_{0} = d_{E}(f(t_{0}), q)$ provided $a \leq t_{0} \leq b$.
Introduce real-valued functions
$$
f_{1}(t) = (f(t) - p) \cdot v,\qquad
f_{2}(t) = (f(t) - p) \cdot n.
$$
Geometrically, we're resolving $f$ into components with the origin at $p$ and the Cartesian axes parallel to $v$ and to $n$, respectively. It suffices to show $f_{2}$ is identically $0$.
If $t_{0}$ is an arbitrary real number in $(a, b)$, then since $b - a = (t_{0} - a) + (b - t_{0})$ and $f$ is an isometry,
\begin{align*}
d_{E}(p, q) &= d_{E}(p, f(t_{0})) + d_{E}(f(t_{0}), q) \\
&= \bigl[(f_{1}(t_{0}) - a)^{2} + f_{2}(t_{0})^{2}\bigr]^{1/2}
+ \bigl[(b - f_{1}(t_{0}))^{2} + f_{2}(t_{0})^{2}\bigr]^{1/2} \\
&\geq |f_{1}(t_{0}) - a| + |b - f_{1}(t_{0})| \geq b - a = d_{E}(p, q);
\end{align*}
consequently, the inequalities are equalities, and the first implies $f_{2}(t_{0}) = 0$. (The second can be used to show $f_{1}(t) = t - a$, so that $f$ is an affine parametrization of $\ell$.)
We conclude that the image of $[a, b]$ is contained in $L$. Since $p$ and $q$ were arbitrary points of $\ell$, we have $\ell \subset L$.
The reverse inclusion is easier: If $p$ is an arbitrary point of $L$, then $d_{E}(f(0), p) = r$ is a real number. If $r = 0$, then $p = f(0) \in \ell$. Otherwise, there are precisely two points of $L$ at Euclidean distance $r$ from $f(0)$, one of them being $p$, and precisely two real numbers of absolute value $r$. Since $f:\Reals \to \ell$ is a bijection, we have either $p = f(r)$ or $p = f(-r)$. In either case, $p \in \ell$.
Best Answer
As was noted in the comments, the extending isometry will not be unique if the subset $X$ is contained in a hyperplane, because an isometry defined on a hyperplane can be extended in many different ways to the whole $\mathbb{R}^n$.
So, assuming the subset $X$ is not contained in any hyperplane, we can choose $(n+1)$ independent points in $X$. We'll do it explicitly. Take any collection of $n$ points in $X$ and consider the hyperplane $H$ they span (if they don't span a hyperplane, add more independent points until they do, which is possible due to the hypothesis). Then choose $n$ independent points $x_1,\dots, x_n$ in $H$. Since $X$ isn't contained in $H$, there is at least one $x\in X$ which doesn't belong to $H$, so that $x_1,\dots, x_n, x$ are $(n+1)$ independent points in $X$.
Now, there's obviously only one isometry $f: \mathbb{R}^n \rightarrow \mathbb{R}^n$ with $f(x_1) = g(x_1)$, $\dots$, $f(x_n) = g(x_n)$, $f(x) = g(x)$. This isometry also coincides with $g$ at any other point in $X$, because $g$ is also completely determined by how it transforms the $(n+1)$ chosen points.