Intuitively, what does being a UFD have to do with line bundles/first homology In this question I asked for geometric clarification of the fact $\mathbb R[x,y,z]/ \left\langle x^2+y^2+z^2 -1 \right\rangle$ is a UFD in contrast to $\mathbb R[x,y]/ \left\langle x^2+y^2 -1 \right\rangle$.
The answer pointed to connections to the class group, and then the Picard group and therefore line bundles.
That's all great, but I would like naive geometric intuition as to why non-unique factorizations hint at non-trivial line bundles/first homology. First instance the circle has two distinct factorizations $$y\cdot y=y^2\equiv_{\mathbb S^1}1-x^2=(1+x)(1-x)$$ but I don't understand what this non-uniqueness is saying geometrically.
What's the picture here?
 A: I'm not sure if this is exactly what you're looking for, but the equivalence of $y^2$ and $(1 - x)(1 + x)$ for $\mathbf{S}^1$ says that you can look at the divisor $D = 2((1,0) + (-1,0))$ in two ways:


*

*By intersecting the lines $x = \pm 1$ with the circle (the lines are tangent so the intersection has multiplicity $2$)

*By intersecting the line $y = 0$ with the circle. The points above are doubled so really we want the doubled line $y^2 = 0$.
So we have $D = \mathcal{V}(y^2) = \mathcal{V}((1-x)(1+x))$.
Also notice that every principal divisor $\mathcal{V}(f)$ on $\mathbf{S}^1$ has even degree. For example, every line intersects the circle in two distinct points or one doubled point (a tangential intersection). This classifies the principal divisors (i.e. every even degree divisor is principal).
So ${\rm Cl}(\mathbf S^1) = \mathbf Z/2$. The problem here, is somehow we want to be able to break our divisor $D$ up into 4 parts, not just two. That is, if $(1,0) = \mathcal{V}(f)$ and $(-1,0) = \mathcal{V}(g)$ then we could say
$$ \mathcal{V}(y) = \mathcal{V}(fg), \mathcal{V}(1-x) = \mathcal{V}(f^2), \mathcal{V}(1 + x) = \mathcal{V}(g^2) $$
Which would give us $y^2 = (fg)^2$ and $(1 - x)(1 + x) = (f^2)(g^2)$ (up to a constant) so that $y^2$ and $(1 - x)(1 + x)$ represent the same factorization. But $(1,0)$ and $(-1,0)$ are not principal divisors so we don't get this.
A: Suppose $a,b,c,d\in R$ are powers of prime elements satisfying $ab=cd$. Let us write $a\sim_R c$ when $a,c$ are associates in $R$. Failure of $R$ to be a UFD means $$\neg (a\sim c\;\vee\;a\sim d).$$
A possible cause for this is that the disjunction holds locally but not globally. In other words, there may be some open cover $(U_i)_{i\in I}$ of $\operatorname{Spec}R$ such that $$\forall i\in I\;(a\sim_{U_i} c\;\vee\;a\sim_{U_i} d),$$ but such that exist $i\neq j$ such that only $a\sim_{U_i} c$ while only $a\sim_{U_j} d$.
(This already hints at some involvement of (co)homology as an obstruction to globalizing.)
Let us suppose indeed that only $a\sim_{U_i} c$ and only $a\sim_{U_j} d$. By further localizing each case, say at $c,d$ respectively, the associate condition becomes 
$$a|_{D_c}\in R_c^\times, \; a|_{D_d}\in R_d^\times. $$
Thus $a\in R$ is invertible on each of the principal opens $D_c,D_d$, and yet it is not invertible on their union. This means the shape of the scheme $(\operatorname{Spec}R,R)$ is in some sense complicated.
This seems related to homology, although the $a\in R$ is a global function. What doesn't globalize is local invertibility. I don't see a naive connection to line bundles yet either.
In the example of the circle $R=\frac{\mathbb R[x,y]}{ \left\langle x ^2+y^2-1 \right\rangle }$, we have the open cover $D_{1-y},D_{1+y}$ by two arcs-minus-a-point. On each of them, the regular function $x\in R$ is invertible: on $D_{1-y}$ we have that $\frac{x}{1-y}$ is a unit and on $D_{1+y}$ we have that $\frac{x}{1+y}$ is a unit. However, $x\notin R^\times$. Indeed every coset in $R$ has a unique representative of the form $f_1+yf_2$ for $f_1,f_2\in \mathbb R[x]$ and such representatives can be used to calculate $R^\times$ and infer $x\notin R^\times $ (I think).
