When using PIN_PD6 as output and writing via digitalWrite(PIN_PD6, 0), the pin loses the direction bit, i.e. PORTD.DIR bit 6 is cleared. This is caused by the turnOffPWM() function in wiring_digital.c. At the very and of this function, if the output pin is DACOUT it will be switched to input. I have no idea why this piece of code is there anyway, it should be deleted.