With a view to understand to which extent OP's identity can fail, I am sharing these easy **positive results**. The emphasis is on the fact that OP's question tightly relates to (generalizations of) the prime avoidance lemma for ideals of denominators.

Let $A$ be an integral domain. Let $(\mathfrak{p}_i)_{i \in I }$ be an arbitrary family of prime ideals of $A$. Let $S = A \setminus \bigcup_{i \in I} \mathfrak{p}_i$.

**Claim 1.** The inclusion $S^{-1}A \subset \bigcap_{i \in I} A_{\mathfrak{p}_i}$ always holds. If moreover $\{\mathfrak{p}_i\}_{i \in I}$ contains the set of all maximal ideals of $A$, then $A = S^{-1}A = \bigcap_{i \in I} A_{\mathfrak{p}_i}$.

*Proof.* Elementary, see e.g., [1, Theorem 4.7].

Let $R$ be an arbitrary commutative ring with identity. We say that $R$ satisfies the *prime avoidance lemma for unions of cardinality $\kappa$* if for every ideal $I$ of $R$ and every index set $K$ of cardinality $\kappa$, the inclusion $I \subset \bigcup_{k \in K} P_k$ implies $I \subset P_l$ for some $l \in K$, where the ideals $P_k$ are arbitrary prime ideals of $R$.

Note that the prime avoidance lemma for countable unions holds for some interesting classes of rings, see for instance the answer of Neil Epstein to this MO post. For more on prime avoidance, I recommend [Exercises 3.16 to 3.20, 2]. The bleeding-edge results on infinite prime avoidance are as of today in [3].

**Claim 2.** If $A$ is GCD domain, or satisfies the prime avoidance lemma for unions of cardinality $\vert I \vert$, then $S^{-1}A = \bigcap_{i \in I} A_{\mathfrak{p}_i}$.

*Proof.* Let $x \in \bigcap_{i \in I} A_{\mathfrak{p}_i}$ and let $\mathfrak{d} = \{ d \in A \, \vert \, dx \in A \}$ be the *ideal of denominators of $x$*. Then we have $\mathfrak{d} \not\subset \mathfrak{p}_i$ for every $i \in I$. If $A$ is a GCD domain, then $\mathfrak{d}$ is a principal ideal generated by some $d_x \in S$, thus $x \in S^{-1}A$. If $A$ satisfies the prime avoidance lemma for unions of cardinality $\vert I \vert$, then we certainly have $\mathfrak{d} \cap S \neq \emptyset$, so that $x$ has a denominator in $S$.

[1] H. Matsumura, "Commutative Ring Theory", 1986.

[2] D. Eisenbud, "Commutative Algebra with a View Toward Algebraic Geometry", 1995.

[3] J. Chen, "Infinite prime avoidance", 2017.