Given $x,y \in \Bbb R^n$ , we have $||f(x)-f(y)|| \leq (\sup_{p\in [x,y]} ||Df_p||)||x-y|| = ||x-y|| \ldots(*)$ (By Mean Value Theorem) since , $Df_p \in O(n,\Bbb R) \forall p \in [x,y]$ where, $[x,y] = \{(1-t)x+ty : t \in [0,1]\}$ .
Given any point $x \in \Bbb R^n$ , $Df_x \in O(n,\Bbb R) \implies Df_x \in GL(n,\Bbb R)$ .Now applying Inverse function theorem we get a neighborhood $U$ of $x$ and a neighborhood $V$ of $f(x)$ such that $f:U \to V$ and $g := f^{-1} : V \to U$ are $C^1$ maps that are one-one and onto. Since, $Df_x \in O(n,\Bbb R) \implies Dg_{f(x)} \in O(n,\Bbb R)$ and hence , we again get in $V$,$$||g(f(x))-g(f(y))|| \leq (\sup_{q\in [f(x),f(y)]} ||Df_q||)||f(x)-f(y)|| = ||f(x)-f(y)|| \ldots(**)$$ while $[f(x),f(y)] \subset V$ .
Combining $(*)$ and $(**)$ we get that $||f(x)-f(y) || = ||x-y||$ while $[x,y] \subset U$ and $ [f(x),f(y)] \subset V$ that is an isometry at a 'local' stage, since the above arguments are valid $\forall x,y \in \Bbb R^n$ .
Now fix a non-zero vector $v \in \Bbb R^n$ and consider $ s := \inf \{|\lambda| : |\lambda| > |\beta| \text { and } f(\beta v)=\beta f(v)\} $ . If $s < +\infty$ , then $\exists \lambda_0$ such that $f(\lambda_0 v) $ is not lying on the direction $v$ (on the straight line $\{w: w=cv\}$) i.e. it is going 'bend' in some direction and then it violates the 'local' isometry property we established earlier .
Hence $f(\lambda v) = \lambda f(v) \forall \lambda \in \Bbb R$ .Since , $v$ was arbitrarily chosen, so in particular, $f$ maps 'straight-lines' to 'straight-lines' keeping length unaltered (easy to see).
So it is of the desired form.