Position a rack in the lower third of the oven and preheat to 400°F.
About 15 minutes before rolling out the pie dough, remove it from the refrigerator to soften slightly. Lightly flour a clean work surface and a rolling pin. Roll out one of the pieces of dough into an even, ¼-inch-thick circle, then carefully lift the dough into a 9-inch aluminum or glass pie plate. Use a sharp knife to trim the edges, leaving 1 inch of overhang all the way around.
In a large bowl, stir together the flour, sugar, cinnamon, nutmeg, and salt. Add the blueberries and vanilla and toss well to coat, then transfer the filling to the pie shell, mounding the berries slightly in the center. Dot the surface of the berries with the butter.
Once again, lightly flour your work surface and rolling pin. Roll out the second piece of dough into an even, ¼-inch-thick circle, then carefully lift the dough and place it over the berry mixture. Use a sharp knife to trim the edges, leaving about 1½ inches of overhang all the way around, then tuck the edges of the top crust under the edges of the bottom crust. Pinch the edges together decoratively to seal, or use the tines of a fork to crimp all the way around. Using the tip of a paring knife, make 6–8 slits on the surface of the crust to vent. Place the pie in the freezer just until the crust is firm, about 15 minutes.
In a small bowl, whisk together the milk and egg yolk. Brush the surface of the pie crust with the egg wash and sprinkle with coarse sugar, if using. Place the pie on a large, rimmed baking sheet and bake until the crust is set and just beginning to brown, 20–25 minutes. Turn the temperature to 350°F and continue baking until the crust is evenly golden brown and the juices are bubbling and thickened, 30–40 minutes more for fresh berries or 60–70 minutes more for frozen. (If the edges begin to darken before the filling has thickened, cover them with strips of aluminum foil to finish baking.) Cool to room temperature before cutting into slices and serving.