I don't think they need to do much in response to the PS5 and Xbox Scarlett specifically since the stationary systems are selling on different points compared to the portable Switch. Of course, though, in order to remain relevant overall for customers they are going to need to continue with a largely sustained and consistent output of quality games.
I do think, however, that they should ensure they do not wait too long to release a successor to the Switch (by which I mean a Switch 2, which largely follows the same concept at the Switch, but with more horsepower and more novel additions). This is not necessarily in response to the PS5 or Scarlett, but rather that consoles generally start to slow-down sales wise at around the 5 year mark and I would think that Nintendo wants to have a smooth transition from Switch to Switch 2. I feel that their mistake with the transition from Wii was that they waited too long to introduce an HD console. By the time the Wii U came out, the Wii had gone through a steep sales decline and a full drought year, by which point I feel the brand had become somewhat toxic (certainly the Wii U's own less than stellar launch and marketing did not help matters either mind you). Ideally, they should have something around 2021 or 2022 with software ready right out the gate for it. Of course, Nintendo can take a page out of their own handheld playbook and the playbooks of MS and Sony this gen and release an enhanced revision of the Switch that falls in the same generation (although ideally they shouldn't make exclusives for it again like they did with New 3DS and DSi, since it sends mixed signals to customers and third-party developers) and that can help them prolong the systems sales a bit more. I do also believe that a Switch 2 could co-exist, at least initially, with the Switch Lite as the cheaper option (much like the 2DS and New 2DS XL were until the Switch Lite's introduction). This would allow Nintendo to initially support and capitalize on the current Switch userbase by still releasing smaller releases/remakes (where the Lite keeps the old gen alive through the transition) while aiming newer and larger scale projects at the Switch 2 (and presuming the Switch 2 is backwards compatible with the original, these smaller Switch releases would still run on the newer hardware perhaps even with enhancements, thereby reducing the chance that the new platform would go through first-party or second-party droughts).