If your base field $k$ is algebraically closed (or if $X$ has a rational point), then this follows directly from the fact that the category of $\mathcal{O}_X$-coherent flat connections is neutral Tannakian, i.e. equivalent to the category of finite dimensional $k$-representations of some affine $k$-group scheme $G$. For this fact the Riemann-Hilbert correspondence is not needed, it just gives you additional information about $G$.

Here is a more direct argument: If $E$ is a $D$-module which is coherent as an $\mathcal{O}_X$-module, then $E$ is automatically locally free. In particular, if $E$ is a sub $D$-module of the "constant" $D$-module $\mathcal{O}_X^n$, then the short exact sequence of $D$-modules

$$0\rightarrow E \rightarrow \mathcal{O}^n_X \rightarrow \mathcal{O}^n_X/E\rightarrow 0$$
is locally split as a sequence of $\mathcal{O}_X$-modules.

We see that if $n=1$, then $E=0$ or $E=\mathcal{O}_X$. We proceed by induction.

Since a $D$-module is trivial if and only if there exists a dense open subset of $X$ on which it is trivial, we may work in the local ring of a closed point $x\in X$ (lets assume $X$ to be connected…).

If $e_1,\ldots, e_n$ is a horizontal basis, then the horizontal sections of $\mathcal{O}_X^n$ are precisely those sections which are in the $k$-span of $e_1,\ldots, e_n$. The group of $D$-automorphisms of $\mathcal{O}_X^n$ then identifies with $GL_n(k)$. Thus if $E$ contains a horizontal section, we are done by induction. The case $n=1$ implies that if $E\cap e_i\mathcal{O}_X\neq 0$ for some $i$, then $e_i\in E$. If $f_1e_1+\ldots+f_n e_n$ is a section of $E$, which is not horizontal, then some $f_i\in \mathcal{O}_{X,x}$ is nonconstant, say $f_1$. One finds a differential operator $\partial$, such that $\partial(f_1)\in \mathcal{O}_{X,x}^\times$, and concludes that $E$ intersects the $\mathcal{O}_X$-span of $e_2,\ldots, e_n$ nontrivially. Hence, either $e_1\in E$, or $E\subset \bigoplus_{i\geq 2} e_i\mathcal{O}_X$, and in both cases we are done.