Issues porting capacitive touch code from Arduino to avr

Because the time take between driving pin 8 high and making it an input is very different perhaps? digitalWrite and pinMode have overheads of several microseconds each, whereas the time between

    PORTB |= 1;

and

    DDRB &= ~1;

is a small fraction of a µs as there is almost no overhead, just direct register bit flips. Thus the pulse on the pin lasts a tiny fraction of the time compared to the Arduino code. An explicit delay is needed to define the pulse width.