Let $p:X\rightarrow Y$ be a closed continuous surjective map such that $p^{-1}(y)$ is compact for each $y\in Y$. Show that if $X$ is second countable then $Y$ is second countable.
Let $y\in Y$ and $U$ be an open set in $Y$. Let $x\in X$ such that $p(x)=y$.
As $p$ is continuous, $p^{-1}(U)$ is open and contains $x$.
As $X$ is second countable there exists a countable collection of open sets $\{U_n\}$ being basis for $X$.
We have $x\in X$ and $x\in p^{-1}(U)$. So, there exists $n\in \mathbb{N}$ such that $x\in U_n\subset p^{-1}(U)$..
Do the same for all elements of $p^{-1}(y)$. We then have $p^{-1}(y)\subset \bigcup_{n=1}^{\infty} U_n$.
As $p^{-1}(y)$ is compact there exists a finite subcover. We then have $p^{-1}(y)\subset \bigcup_{i=1}^n U_i\subset p^{-1}(U)$.
Set $M=\bigcup_{i=1}^n U_i$ for simplicity of notation.
Claim is that $y\in p(M^c)^c\subset U$.
Suppose $y\notin p(M^c)^c$ then $y\in p(M^c)$ then $y=p(a)$ for some $a\in M^c$. But then $a\in p^{-1}(y)\subset M$. So, $a\in M$ and $a\in M^c$ a contradiction. So, we do have $y\in p(M^c)^c$
Suppose $m\in U^c$ and $p(a)=m$. We then have $a\in p^{-1}(m)\subset p^{-1}(U^c)\subset p^{-1}(U)^c\subset M^c$. So, $p(a)=m$ for some $a\in M^c$ i.e., $m=p(a)\in p(M^c)$ and so $y\notin p(M^c)^c$.
So, $y\in p(M^c)^c\subset U$.
So, we have a countable collection $$\left\{p\left(\bigcap_{i=1}^n U_i^c\right)^c:n\in \mathbb{N}\right\}$$ is a countable basis for $Y$.
Let me know if there are any gaps.
The basic idea is fine, but there are some problems with the notation, and the organization could be better.
The worst notational problem is when you write that $p^{-1}(y)\subset\bigcup_{n=1}^\infty U_n$. Since the sets $U_n$ in this union were obtained as nbhds of points of $p^{-1}[\{y\}]$, you seem to be assuming here that $p^{-1}[\{y\}]$ is countably infinite, when in fact it could be finite or uncountable. Moreover, your countable base for $X$ was $\{U_n:n\in\Bbb N\}$, so the union of the sets $U_n$ is all of $X$; this does indeed contain $p^{-1}[\{y\}]$, but in general it will not be a subset of $p^{-1}[U]$. To avoid this problem you could say that for each $x\in p^{-1}[\{y\}]$ there is an $n(x)\in\Bbb N$ such that $x\in U_{n(x)}\subseteq p^{-1}[\{y\}]$. Then you could observe that $\{U_{n(x)}:p(x)=y\}$, being an open cover of the compact set $p^{-1}[\{y\}]$, has a finite subcover $\{U_{n(x_1)},\ldots,U_{n(x_m)}\}$ for some $x_1,\ldots,x_m\in p^{-1}[\{y\}]$, and let $M=\bigcup_{k=1}^mU_{n(x_k)}$.
I would change the organization completely: I would start with a countable base $\mathscr{B}$ for $X$. I would then show that if we take the closure of $\mathscr{B}$ under finite unions, we still have a countable base for $X$, so we might as well assume that $\mathscr{B}$ is already closed under finite unions. Then I would prove that
$$\big\{Y\setminus p[X\setminus B]:B\in\mathscr{B}\big\}$$
is a countable base for $Y$.
That proof is essentially your argument. Let $U$ be a non-empty open set in $Y$, and let $y\in U$. For each $x\in p^{-1}[\{y\}]$ there is a $B_x\in\mathscr{B}$ such that $x\in B_x\subseteq p^{-1}[U]$. The family $\{B_x:p(x)=y\}$ is an open cover of the compact set $p^{-1}[\{y\}]$, so there is a finite $F\subseteq p^{-1}[\{y\}]$ such that $p^{-1}[\{y\}]\subseteq\bigcup\{B_x:x\in F\}$. And $\mathscr{B}$ is closed under finite intersections, so $\bigcup\{B_x:x\in F\}\in\mathscr{B}$; let $B(y)=\bigcup\{B_x:x\in F\}$. (This $B(y)$ corresponds to your $M$.)
$X\setminus B(y)$ is closed in $X$, so $p[X\setminus B(y)]$ is closed in $Y$, and $Y\setminus p[X\setminus B(y)]$ is open in $Y$. Moreover, $p^{-1}[\{y\}]\cap\big(X\setminus B(y)\big)=\varnothing$, so $y\notin p[X\setminus B(y)]$, and therefore $Y\setminus p[X\setminus B(y)]$ is an open nbhd of $y$. All that remains is to show that $Y\setminus p[X\setminus B(y)]\subseteq U$, which can be done directly. Let $u\in Y\setminus p[X\setminus B(y)]$; there is some $x\in X$ such that $u=p(x)$. Clearly $x\notin X\setminus B(y)$, so $x\in B(y)\subseteq p^{-1}[U]$, and $u=p(x)\in U$.