So, here's the full question:
Let $f:(X,d) \to (Y,d')$ be a function between two metric spaces. $f$ is continuous iff for each open set $O \subseteq Y$, $f^{-1}(O)$ is an open subset of $X$.
Proof Attempt:
Let $f: (X,d) \to (Y,d')$ be a function between two metric spaces and suppose that $f$ is continuous.
Let $O$ be an open set of $Y$. To prove that $f^{-1}(O)$ is open, we need to show that it is a neighbourhood of each of its points. Let $p \in f^{-1}(O)$ be arbitrary but fixed. Then, $f(p) \in O$. Since, $O$ is a neighbourhood of $f(p)$ and $f$ is continuous, $f^{-1}(O)$ is a neighbourhood of $p$ and, therefore, of each of its points. Hence, $f^{-1}(O)$ is an open subset of $X$.
Now, suppose that for each open set $O$ of $Y$, $f^{-1}(O)$ is an open subset of $X$. Let $a \in X$ be arbitrary but fixed. Let $M$ be a neighbourhood of $f(a)$. Then:
$$\exists \epsilon > 0: S'(f(a),\epsilon) \subseteq M$$
Since $S'(f(a),\epsilon)$ is an open set, we can see that $f^{-1}(S'(f(a),\epsilon))$ is an open set. So, it follows that it is a neighbourhood of $a$. In particular, since it is the case that:
$$f^{-1}(S'(f(a),\epsilon)) \subseteq f^{-1}(M)$$
it follows that $f^{-1}(M)$ is a neighbourhood of $a$. That proves that $f$ is continuous at $a \in X$ and, therefore, continuous.
Does the proof above work? If it doesn't, why? How can I fix it?
Here I provide a slightly different way to prove the proposed result.
Let us start with the implication $(\Rightarrow)$ first.
Let $\mathcal{O}\subseteq Y$ be an open set. Then we have to prove that $f^{-1}(\mathcal{O})$ is open.
In order to do so, let's consider that $x\in f^{-1}(\mathcal{O})$.
Then $f(x)\in\mathcal{O}$. Since $\mathcal{O}$ is open, there exists an $\varepsilon > 0$ such that $f(x)\in N_{\varepsilon}(f(x))\subseteq\mathcal{O} $.
Consequently, due to the continuity of $f$, we conclude there is a $\delta > 0$ s.t. \begin{align*} y\in N_{\delta}(x) \Rightarrow f(y)\in N_{\varepsilon}(f(x))\subseteq\mathcal{O} \Rightarrow y\in f^{-1}(\mathcal{O}) \end{align*}
which proves that $x\in N_{\delta}(x)\subseteq f^{-1}(\mathcal{O})$, whence we conclude that $f^{-1}(\mathcal{O})$ is open.
We may now approach the second implication $(\Leftarrow)$.
We have to prove that for every $\varepsilon > 0$ and every $x_{0}\in X$, there corresponds a $\delta > 0$ s.t. for every $x\in X$ \begin{align*} d_{X}(x,x_{0}) < \delta \Rightarrow d_{Y}(f(x),f(x_{0})) < \varepsilon \end{align*}
Let $x_{0}\in X$ and $\varepsilon > 0$.
If we consider any open ball $N_{\varepsilon}(f(x_{0}))\subseteq Y$, we know that $f^{-1}(N_{\varepsilon}(f(x_{0}))$ is open due to the given assumption.
Since $x_{0}\in f^{-1}(N_{\varepsilon}(f(x_{0}))$, there exists an open ball s.t. $x_{0}\in N_{\delta}(x_{0})\subseteq f^{-1}(N_{\varepsilon}(f(x_{0}))$.
Finally, we conclude that for every $x_{0}\in X$ and every $\varepsilon > 0$, there corresponds a $\delta > 0$ s.t. \begin{align*} x\in N_{\delta}(x_{0}) \Rightarrow f(x)\in N_{\varepsilon}(f(x_{0})) \end{align*}
and we are done. Hopefully this helps.