Here is an answer based on my comment, and Geoff Robinson's earlier comment.
Let $A$ be a domain with $2\in A^\times$, and let $M$ be an $n\times n$ matrix with $M^2=I$. It is convenient to consider $M$ as an $A$-endomorphism of $A^n$ and $I$ as the identity endomorphism of $A^n$. Put $S_+ =\{x\in A^n\,:\,Mx=x\}$ and $S_-=\{x\in A^n\,:\,Mx=-x\}$. As noted in Geoff Robinson's comment, since $2\in A^\times$, we have
$A^n=S_+\oplus S_-$. (This follows readily from the fact that $x=\frac{1}{2}(x+Mx)+\frac{1}{2}(x-Mx)$ for all $x\in A^n$ and $M^2=I$.) In particular, both $S_+$ and $S_-$ are f.g. projective $A$-modules.
Suppose that every f.g. projective $A$-module is free. Then $S_+$ and $S_-$ are free. Let $E_+$ and $E_-$ be bases for these spaces. Then $E=E_+\cup E_-$ is a basis of $A^n$ consisting of eigenvalues of $M$, which means that $M$ is a diagonalizable.
On the other hand, if there exists a f.g. projective $A$-module $P$ which is not free, then we can construct a non-diagonalizable involution $M:A^n\to A^n$ as follows. There exists a f.g. $A$-module $Q$ such that $A^n\cong P\oplus Q$ for some $n\in\mathbb{N}$. Now take $M$ to be the matrix corresponding to $\mathrm{id}_P\oplus (-\mathrm{id}_Q)$. For this $M$, we have $S_+=P$ and $S_-=Q$. If $M$ were diagonalizable, then $A^n$ would have a basis $E$ consisting of vectors $x\in A^n$ with $Mx\in \{\pm x\}$ (here we need $A$ to be a domain). Consequently, $E = (E\cap S_+)\cup (E\cap S_-)$, which means that $E_+:=E\cap S_+$ is a basis of $S_+=P$. This contradicts our choice of $P$, so $M$ is not diagonalizable.
There are examples of UFDs admitting f.g. projective modules which are not free --- see this question, for instance. Quoting from this answer, one can take $A=\mathbb{C}[a,b,c,x,y,z]/(ax+by+cz-1)$, the module $P$ to be the kernel of $(\alpha,\beta,\gamma)\mapsto a\alpha+b\beta+c\gamma:A^3\to A$, and $Q=(x,y,z)A$. One has $P\oplus Q=A^3$, so it should be possible to write the resulting $M\in \mathrm{M}_3(A)$ explicitly.