repl history implementation improvements

Addresses comments in #2886

* Replace large comprehension with much simpler code
* fix comment to reference maxSize instead of previous 10KB limit
* only pop a history entry if the file size is actually bigger than maxSize
* only add items to the history if they are different from the last item by storing the last line and loading it on startup.