If I'm going to caulk the gap anyway, I usually use a tape measure and put a few marks on the stile, and connect them with a straight-edge. But, if it's a custom cherry bookcase, I'll take a little more time and make it look perfect. I install the cabinet first without the wall side stile on. Then, I measure from the end of the top rail to the wall. Next, I transfer that measurement onto the stile.
Tape usually holds it well enough.
Now you're ready to scribe. Take a compass, with a sharp pencil, and set it to the distance between the wall and the pencil mark on the stile. With the pencil side on the stile, slide the compass down the wall. Get a good compass or dividers that lock. It makes it hard to scribe when you use those 99 cent compasses.