Closedness with respect to an open cover

This is something that came up when I was studying something else, but I am wondering whether the following topological fact is true.

Let $X$ be a topological space, and $\{U_i\}_{i=1}^n$ a finite open cover of $X$. Let $A \subseteq X$ be a subset such that $A \cap U_i$ is closed in $U_i$ for all $i$. Then $A$ is closed in $X$.

(If this turns out to be false, is there a counterexample such that each $U_i$ is also dense in $X$?)

There is probably something simple that I am overlooking, so any help would be greatly appreciated.

Note that $A\cap U_i=U_i\cap C_i$ for $C_i$ closed in $X$. Then \begin{align} A &= (A\cap U_1)\cup\dotsb\cup(A\cap U_n) \\ &= (U_1\cap C_1)\cup\dotsb\cup(U_n\cap C_n) \\ &= (U_1\cup\dotsb\cup U_n)\cap(C_1\cup\dotsb\cup C_n) \\ &= X\cap(C_1\cup\dotsb\cup C_n) \\ &= C_1\cup\dotsb\cup C_n \end{align} so $A$ is closed.
It seems you are right and $X\backslash A=\bigcup U_i\backslash A=\bigcup U_i\backslash (U_i\cap A)$ is open as a union of open sets.