Join on dm_db_index_physical_stats very slow
The disk activity is high because it needs to pull your whole database into RAM to do its analysis. If you call sys.dm_db_index_physical_stats with fewer NULLs, it will be able to run your query on a subsection of the database, which will then run much quicker.

Sadly, your TOP 1 isn't stopping it from doing all the calculations, as you're calling the main function with all those NULLs.