I am wondering why this theorem is not true when $(f,g)$ are defined on a more general open set $U$ which is not necessarily the entire plane or some disc. What is an example of a vector field
$$F(x,y)=(f(x,y),g(x,y))$$ defined on some open set $U$ satisfying the condition $$\frac{\partial f}{\partial y} = \frac{\partial g}{\partial x}$$ but $F$ does not have a potential function?

The vector field $(f(x,y),g(x,y))=\left(\frac{y}{x^2+y^2},\frac{-x}{x^2+y^2}\right)$ has $$\frac{\partial f}{\partial y} = \frac{1}{x^2+y^2}-\frac{2y^2}{(x^2+y^2)^2}=\frac{x^2-y^2}{(x^2+y^2)^2}=\frac{2x^2}{(x^2+y^2)^2}-\frac{1}{x^2+y^2}=\frac{\partial g}{\partial x}$$ On an annulus $r<x^2+y^2<R$, this function fails to have a potential function; its integral around a circle centered at the origin (parametrized $(c\cos\theta,c\sin\theta)$ is $$\int_{C}f\,dx+g\,dy = \int_{0}^{2\pi} \frac{c\sin\theta}{c^2}\cdot -c\sin\theta+\frac{-c\cos\theta}{c^2}\cdot c\cos\theta\,d\theta = \int_0^{2\pi}-1\,d\theta=-2\pi$$ But then, if there were a potential function, that integral would have to be zero - the starting and ending points are the same. We can tell that the potential function "should" be the angle $\theta$, but that can't be extended continuously to the whole annulus.
In order to avoid this and examples like it, we need to avoid regions with holes in them - this example depends on the origin being "inside" but not part of the domain. The condition of an open disc or the interior of the rectangle ensures this, as a subset of the broader collection of simply connected open sets.