Vanishing of curvature tensor implies path independence of parallel transport only to second order?
Your question is not trivial and any proof of it that I know uses the Frobenius theorem which is a non-trivial analytic result. Let me give you an analogy which is in fact a particular case of what you're asking. Assume you have a one-form $\omega$ on some open ball $B$ in $\mathbb{R}^n$ and you want to determine a condition which guarantees that the path integral of $\omega$ depends only on the end points. Starting with such $\omega$, fix a point $p \in B$ and define a potential function $f \colon B \rightarrow \mathbb{R}$ by the formula
$$ f(x) = \int_p^x \omega $$
where the integral is done over any path which connects $p$ to $x$. Since $f$ is a smooth function, the second mixed partial derivatives of $f$ must commute and by calculating them, we see that this happens iff $d\omega = 0$. Hence, a necessary condition for the path independence of the integral is that $d\omega = 0$. This is a first order condition on $\omega$. However, by differentiating again we can get higher order conditions on $\omega$ which are also necessary. A priori, it is not clear at all that $d\omega = 0$ should be sufficient to obtain path independence but this is indeed the case which is the content of Poincare's lemma.
The situation with curvature is the same. If you have a rank $k$ vector bundle $E$ over $B$ with a connection, fix some trivialization $(e_1,\dots,e_k)$ and consider the associated connection $1$-form $\omega$ which is a lie-valued one-form. If the parallel transport is independent of the path, you can define a "potential" function $f \colon B \rightarrow \operatorname{GL}_k(\mathbb{R})$ by requiring that
$$ P_{\gamma,p,x}(e_i(p)) = f(x)_{i}^{j} e_j(x). $$
That is, $f(x)$ tells you the matrix you need to "multiply" the frame $(e_1(x),\dots,e_k(x))$ in order to get the parallel transport of the frame $(e_1(p),\dots,e_k(p))$ from $p$ to $x$ along some (any) path. By calculating "the second derivative" of $f$, you'll see that the curvature $d\omega + \omega \wedge \omega$ must vanish and by differentiating again, you'll get other, higher order, necessary conditions in terms of $\omega$ for the path-independence of the parallel transport. However, the condition $d\omega + \omega \wedge \omega = 0$ will turn out to be sufficient by the Frobenius theorem.
If $E$ is a rank $1$-bundle then $\omega$ is a $\mathbb{R}$-valued form and the curvature becomes $d\omega$ so everything boils down to the previous case (and indeed, the Poincare lemma can be proved using the Frobenius theorem).
Let $\pi:P\to M$ denote the frame bundle, which is a principal $GL(n)$-bundle over $M$. One of the ways to define a connection on $P$ is by a horizontal lift operator $$\lambda_p:T_{\pi(p)}M\to T_pP$$ for every point $p\in P$ (satisfying an equivariance condiction). In particular, we obtain a splitting$$T_pP=V_p\oplus H_p,$$where $H_p$, the horizontal space, is the image of $\lambda_p$, and $V_p$, the vertical space, is the kernel of $d\pi_p$. The curvature of this connection can be thought of as a 2-form on $M$ whose values are vertical vector fields on $P$ given by$$R(X,Y)(p)=[\lambda_p(X),\lambda_p(Y)]-\lambda_p([X,Y]),$$where $X,Y\in\mathcal{X}(M)$.
If the curvature $R$ vanishes on a neighborhood $U\subset M$, then by the Frobenius theorem, the horizontal distribution on $\pi^{-1}(U)$ is integrable. This means that there is a local parallel frame, or in other words, parallel transport in $U$ is independent of the choice of path.
Now all you have left to do is convince yourself that there is a full correspondence between connections on the frame bundle and the tangent bundle, and that this correspondence extends to curvature on both bundles. This is not trivial, but described in many textbooks.
So here is a much simpler argument, which I find better than my previous answer.
Let $E\to M$ be a vector bundle equipped with a flat connection $\nabla$. Let $p,q\in M$, and let $\gamma_0,\gamma_1:[0,1]\to M$ be two homotopic paths connecting $p$ and $q$. Let $v\in E_p$, and we would like to show that the images of $v$ under parallel transport along $\gamma_0$ and $\gamma_1$ are the same.
By assumption, there exists a homotopy $$H:[0,1]\times[0,1]\to M$$ satisfying $$H(0,t)=\gamma_0(t),\;H(1,t)=\gamma_1(t),\;H(s,0)=p,\;H(s,1)=q.$$We construct a section $\sigma$ of $E$ along $H$ (that is, $\sigma$ is a section of the pullback bundle $H^*E$) as follows. We set $\sigma(s,0)=v$ for $s\in[0,1]$ (this makes sense, as $H(s,0)=p$) and extend $\sigma$ to $[0,1]\times[0,1]$ so that it is everywhere parallel in the $t$ direction. We need to show that $\sigma(0,1)=\sigma(1,1)$.
By construction, we have $\nabla_t\sigma\equiv0,$ and so $\nabla_s\nabla_t\sigma\equiv0.$ As $\nabla$ is flat, we deduce $\nabla_t\nabla_s\sigma\equiv0.$ But at $t=0$ we have $\nabla_s\sigma=0$, as $\sigma$ is constant on this side of the square, and hence, we also have $\nabla_s\sigma=0$ at $t=1$. This means that $\sigma$ is constant on this side of the square, too, and in particular, $\sigma(0,1)=\sigma(1,1)$, as desired.