Here is the proof:
Let $A$ be a set, and $\mathcal{P}$ be a property not mentioning the set $B$. Consider the formula $\phi(x, y)$ that means $y=x$ and $\mathcal{P}(x)$ is true. Clearly $(\forall x \in A) \forall y_1 \forall y_2$, $\phi(x, y_1) \wedge\phi(x, y_2)$ implies $y_1=x=y_2$. Therefore, by the replacement axiom schema on the formula $\phi(x, y)$, there exists a set $B$ such that $\forall y$, $y\in B \iff \exists x\in A : \phi(x, y) \iff \exists x\in A : y=x \wedge \mathcal{P}(x) \text{ is true}$.
The part that most worries me about this proof is wether I have defined the formula $\phi(x, y)$ correctly, because I have only assigned it meaning for the $x$'s such that $\mathcal{P}(x)$ is true.