In theory but too risky
Did Japan really have to attack the United States and their interests?
Could Japan have just attacked the Allies in the Pacific and left America alone? Or were they sure the USA would get in on the war and just wanted to be sure they wouldn't be able to be a formidable foe if and when they happens?
Yes. And NO, even NFW.
It would have been better in most respects better for Japan to avoid attacking the US, obviously. What it wanted was the resources of SE Asia to continue its attempts to gain hegemony in China. BUT, this would leave the USN with bases in the Philippines sitting on the supply lines back to the Home Islands and able to cut them pretty much at will. As you say, the Japanese couldn't be certain enough that the US wouldn't join the war on the side of the European colonial powers. It might not, I'm sure experts on 1940s US politics can give a better answer than me on the probability of it DOWing Japan without Pearl Harbour. What's more relevant is that the Japanese thought the risks of that were too great, and, as you say, decided they needed to weaken the USN to give them time to build an "impregnable" buffer zone around Japan. As well as seize the Philippines of course.
I think it's been discussed before here and my opinion is that of the two BAD options, attacking the US was slightly worse than not attacking it. But I don't think that's the consensus and I dont have a great deal of confidence in my view. It was the case that the Japanese establishment believed itself to be backed into a corner with no viable options other than seizing SE Asia. And their answer to the dilemma differs from mine.