That's because office 365 page is always at scrollTop:0
position.
You will see in the office 365 page that scrolling appears after ribbon gets over. Scrolling doesn't apply for whole page, instead it applies to specific div.
While other sites don't have similar scenario and they works with your code.

so If you see in browser developer tool #s4-workspace
is the specific element which has scrolling. So what your script does is move to top window, which is already at top.
So if you want to make it work, you need to do it with jQuery and then can specify below code in console of developer tool:
$('#s4-workspace').animate({ scrollTop: 0}, 'slow');
This will work only if jQuery is loaded. Other way is you can do it with below JavaScript snippet, read more here:
var elmnt = document.getElementById("s4-workspace");
elmnt.scrollTop = 0
Hope this helps!