As a faculty member, I can tell you that if a writing sample is optional, it really is optional (at least for us). I might skim through it just to get a basic sense of the writing, but I won't look at it very closely. In fact, I'd probably suggest against including one unless you KNOW it's stellar, because I could see myself, all other things equal, likely to veto someone based on a sub-par writing sample. That is, a good writing sample won't help much, but a less great one could hurt you. Of course, that's just me, and I'm but one of hundreds of potential PIs out there, so take my words with a grain of salt!