Slowly, an account of Matthew Perry’s fragmenting last days has been pieced together. It’s a desperate tale