Yes, you could do that but it is important to remember that wills (at least in the United States) are matters of public record, which means that after the will is filed, anyone could go to the relevant county's courthouse (or access its records via website for a small fee) and read the contents of the will. So you would probably not want to put your actual private key in there, although you could still make a general bequest of your bitcoin balance to your successor.
Safe deposit boxes also carry some risks, like the risk of an unscrupulous bank official having access to your stuff, or the risk of either bank or government confiscation should there be a "bail in" to recapitalize the banks during a financial crisis, or perhaps a change in the laws regarding private assets held at banks.