If the scheme $X$ is locally factorial, can it be covered by affine opens of the form $\operatorname{Spec} A$ for $A$ a UFD? More precisely, if $X$ is a scheme such that for all $x\in X$, the ring $\mathscr{O}_{X,x}$ is a UFD, then is it true that we can cover $X$ by affine opens $U = \operatorname{Spec}A$ such that $A$ is a UFD?
Clearly the converse holds true; if we are given an affine scheme of the form $X=\operatorname{Spec}A$ for $A$ a UFD, then since the property of being a UFD is preserved by localization, $X$ is locally factorial. However, it is emphatically not true that given a locally factorial scheme $X$, any affine open $\operatorname{Spec}A$ has $A$ a UFD – for a counterexample, we need only consider $X=\operatorname{Spec}A$ where $A$ is a Dedekind domain with nontrivial ideal class group.
Therefore, my question reduces to the following problem in commutative algebra. Given a ring $A$ such that $A_\mathfrak{p}$ is a UFD for all $\mathfrak{p}\in\operatorname{Spec}A$, then for all $\mathfrak{p}\in\operatorname{Spec}A$, can we find some element $f\in A\setminus\mathfrak{p}$ such that $A_f$ is a UFD?
I don't see any clear answer to this question. My hunch is that it's not true, however.
 A: Let $X$ be a smooth connected projective curve over $\mathbb C$ of genus $g\gt 0$.
Since $X$ is smooth all local rings $\mathcal O_{X,x}$ are UFD's,  but I claim that no affine open subset $U\subset X$ has a ring of regular functions $\mathcal O_X(U)$ which is a UFD.
Proof:
A subset $U\subset X$ is open and affine if and only it is obtained from $X$ by deleting a nonzero finite number of points from $X$ , namely  $U=X\setminus \{x_1,\cdots,x_n\} \quad (n\geq 1)$.
The key tool is then the exact sequence $$\oplus _{i=1}^n\mathbb Z\cdot e_i \stackrel {u}\to \operatorname {Pic}(X) \stackrel {v}\to   \operatorname {Pic}(U) \to 0           $$ in which the map $u$ sends the basis vector $e_i$ of the free module $\oplus _{i=1}^n\mathbb Z\cdot e_i$ to the line bundle $\mathcal O_X(x_i)$, while $v$ is just the restriction to $U$ of line bundles on $X$ . (Beware that $u$ nedn't be injective!)
This exact sequence can be found for $n=1$ in Hartshorne (Chapter II, Prop.6.5, page 133) and in Fulton's IntersectionTheory (Chap.1, Prop 1.8, page 21) for arbitrary $n$.  
Since $\operatorname {Pic}(X)$ is non denumerable (for example because distinct points $x\in X$ give rise to distinct line bundles $\mathcal O_X(x)$ and $X$ is non denumerable since we are over $\mathbb C$) this proves that $\operatorname {Pic}(U)\neq0$.
And this allows us to conclude, as announced, that $\mathcal O_X(U)$ is not a UFD:
Indeed a noetherian domain $A$ is a UFD if and only if every prime ideal of height $1$ in $A$ is principal (Matsumura, Theorem 20.1, page 161) and that last condition translates for $A=\mathcal O(U)$ to every line bundle on $U$ being trivial.
