Have you tried
(replace-regexp "^\n+" "\n")
Replace any number of blank lines with one blank line. This works regardless of the end-of-line style (Unix,DOS,Mac).
Interactively, you can do the same by entering the newlines as literal newline characters, i.e.
M-x query-replace-regexp RET ^C-jC-j RET C-j
This answer uses following answer's code with a small change Can page-down clamp the last line to the bottom of the window?. I just replaced (my-scroll-and-clamp--forward-line height) with (end-of-buffer) that is followed by the set-window-start section.
(defun my-bottom ()
(let* ((height (window-height)))
(end-of-buffer) ;; I added ...