What are the underlying circumstances that make the digitalWrite() and analogWrite() scenarios different ?
digitalWrite() turns a pin on or off. analogWrite() turns the pin on and off very fast, so that the duty cycle is what you specify (as a percentage of 255).
They are not interchangeable.