Let $k$ be a field and let $R$ be a UFD, which is a $k$-algebra. Let $w$ be an algebraic element over $R$, namely, there exists a polynomial $f(T) \in R[T]$ such that $f(w)=0$. Denote $S=R[w]$.
Examples:
(1) $R=k[x^2]$, $w=x^3$, $f(T)=T^2-x^2x^2x^2$, $S=k[x^2,x^3]$.
(2) $R=\mathbb{Z}$, $w=\frac{1}{2}$, $f(T)=2T-1$, $S=\mathbb{Z}[\frac{1}{2}]$.
(3) $R=\mathbb{Q}$, $w=\sqrt{2}$, $f(T)=T^2-2$, $S=\mathbb{Q}[\sqrt{2}]$.
(4) $R=\mathbb{R}$, $w=i$, $f(T)=T^2+1$, $S=\mathbb{R}[i]=\mathbb{C}$.
If I am not wrong, $S$ is a UFD + $w$ is prime or invertible in $S$, in examples (2),(3),(4). In contrast, $S$ is not a UFD and $w$ is not a prime ($x^3$ divides $x^2x^2x^2$, but $x^3$ does not divide $x^2$) nor invertible in example (1).
My claim: If $w$ is a prime element of $S$ (or an invertible element of $S$), then $S$ is also a UFD.
Question: Is my claim true? At least if $w$ is a prime element of $S$. I do not mind to further assume that $k=\mathbb{C}$. Indeed, according to the first comment in this question, $x^2+1$ is prime in $S=\mathbb{R}[x^3][x^2+1]=\mathbb{R}[x^3][x^2]$, but $S$ is not a UFD, so we should assume that $k=\mathbb{C}$.
Remark: $w \in S$ is a prime element in $S$ iff $(w)$ is a prime ideal in $S$ iff $S/(w)$ is an integral domain.
Thank you very much!
It is easy to generalize the $k=\mathbb{R}$ counterexample you cite to the $k=\mathbb{C}$ case.
Let $R=\mathbb{C}(t)[x^3]$ and let $w=x^2-t$. Then $S=R[w]$ is not a UFD; for $S\cong\mathbb{C}(t)[x^3,x^2]$, which supports two factorizations of $x^6$.
But $w$ is prime in $S$, as \begin{align*} S/(w)&=\mathbb{C}(t)[x^3,x^2]/(x^2-t) \\ &=\mathbb{C}(t)[tx,t]/(x^2-t) \\ &=\mathbb{C}(t)[x]/(x^2-t) \\ &\cong\mathbb{C}(t)[\sqrt{t}] \\ &\cong\mathbb{C}(\sqrt{t}) \end{align*} is an integral domain.
For a finite-dimensional (over $k$) counterexample, one can take $R/(x^9)$, and proceed as above.Never mind, that's finite-dimensional over $\mathbb{C}(t)$, but not $\mathbb{C}$. In fact, there are no finite-dimensional counterexamples, since then $R$ would be Artinian and (since a domain) a field. But $\mathbb{C}$ has no nontrivial finite-degree field extensions.