Prove that the infimum $i=\inf\{ d(a,y):y\in Y \}$ is always attained if $Y$ is closed. In Solomon's descriptive set theory notes, he asked the following exercise. 

Let $X$ be a separable, completely metrizable by a metric $d$ and contains a dense subset $D\subseteq X.$
  Let $Y\subseteq X$ be closed and let $a\in X \setminus Y.$
  Define 
  $$i = \inf \{ d(a,y):y\in Y \}.$$
  Question: Prove that there is an element $b\in Y$ such that $d(a,b)=i$.

My attempt: For any $n\in\mathbb{N},$ by the definition of infimum, 
$$i+\frac{1}{n} > d(a,b_n)$$
for some $b_n\in Y.$
Then the sequence $(b_n)_{n\geq 1}$ is Cauchy. 
By completeness of $X,$ there exists $b\in X$ such that $(b_n)_{n\geq 1}$ converges to $b.$
Since $Y$ is closed, we have $b\in Y.$
Clearly $d(a,b)\leq i.$
By definition of $b\in Y,$ we have $d(a,b)\geq i.$
Hence, $d(a,b)=i.$
Is my proof correct?
EDITED: As pointed out by @5xum, my proof has a flaw. If this is the case, then how should one prove the statement above? 
 A: Your proof is not OK.

Then the sequence $(b_n)_{n\geq 1}$ is Cauchy.

First of all, you didn't prove this, and second of all, it's not even true. For example, take
$$X=\mathbb R^2\\
Y=\{(x,y)| x^2+y^2=1\}=S_1\\
a=(0,0)$$
Then, the sequence $b_n$ could be $b_n=(0,(-1)^n)$ which is not Cauchy.
A: The statement above is incorrect. It would work if say closed balls were compact ( locally compact is not enough as @Daniel Wainfleet:"s example shows)
Take $X$ the space of continuous functions on $[0,1]$ with norm $\|f\|= \sup_{t\in [0,1]} |f(t)|$, a separable Banach space, so a separable complete metric space. 
Let $$Y = \{ f \in X \mid \int_{0}^{1/2} f(t) dt - \int_{1/2}^1 f(t) dt = 1 \}$$ 
Then $d(0, Y)= 1$, but the distance is not achieved ( checking this is a good exercise). 
A: Let $X=\Bbb R\cup \{a\}$ with $a\not \in \Bbb R.$ For $x,y\in \Bbb R$ let $d(x,y)=\frac {|x-y|}{1+|x-y|}.$ For $x\in \Bbb R$ let $d(a,x)=2-d(x,0).$ 
Let $Y=\Bbb R.$ Then $\inf \{d(a,y):y\in Y\}=1 $ but $d(a,y)=\frac {2+|y|}{1+|y|}>1$ for all $y\in Y.$
Remark. Defining $d(a,x)$ the way I did makes it easier to confirm the triangle inequality in cases involving the point $a.$ E.g. for $x,y\in \Bbb R$ we have $d(x,a)\leq d(x,y)+d(y,a)\iff$ $\iff 2-d(x,0)\leq d(x,y)+2-d(y,0)\iff$ $ d(y,0)\leq d(y,x)+d(x,0).$
