The issue is that adding the "smaller" class decreases the page size by 30 pixels and that causes the page scroll position to change. So if you were scrolled between 100 and 130 pixels down the page then the "smaller" class was added and the page shrinks causing the scroll position to decrease by 30 pixels so you are now between 70 and 100 pixels scrolled, which causes the "smaller" class to be removed and this causes an infinite loop.
I fixed the issue by combining your code for the "back to top" and "smaller" class into a single function and added a range so that it displays if you are scrolled more than 100 pixels down, but doesn't remove unless you are less than 70 pixels down. This allows the 30 pixel page size change to not cause an infinite loop.
I also added a timout delay in the scroll function because that is good practice in general since scroll can be called hundreds of times in a single scrolling event and you really only want your function called one time once the scrolling is complete.
All of my changes were in the includes/fixed/scripts.php page.