Schematic and Arduino sketch that work

I have been constructing a simple 3 x 3 LED matrix which I want to control with an Arduino R2. I want to be able to control the LED's individually to create sequences, initially in this matrix and ultimately in a 3 x 3 x 3 cube. I realise that you can buy chips to do these sort of things but I am doing it to learn about electronics and the Arduino interface. I have attached a circuit diagram of the matrix connected to the Arduino.
When I connect the matrix, (including the transistors and resistors) without the Arduino, to 5v and earth for the approprite LED, they all work as expected.

Then I connected the LED matrix to Arduino pins 10, 11 and 12 to provide power and pins 4, 5 and 6 for grounds. I think this is where it is becoming confusing for me, the concept of digital signals and the subsequent coding. I assumed that if I set pin 12 HIGH and pin 6 LOW then LED 1 would light which it does as long as it is the only LED actually connected to the Arduino via D 12 and D 6 . If I connect up more than one "pair" of wires (power and ground for relevant LED) I get more than one LED flashing even if I use basic code such as ;


void setup ()
{

pinMode (4 , OUTPUT);
pinMode (5 , OUTPUT);
pinMode (6 , OUTPUT);
pinMode (10 , OUTPUT);
pinMode (11 , OUTPUT);
pinMode (12 , OUTPUT);

}
void loop ()
{
digitalWrite( 12 , HIGH);
digitalWrite ( 6 , LOW);
delay(1000);
digitalWrite( 12 , LOW);
digitalWrite ( 6 , HIGH);

delay(1000);
}


I get LED's 1, 4 and 7 flashing with all connections made between matrix and Arduino. But with all connections and the following code where I have not set digital pins 4 and 5 as OUTPUTS, I get LED's 1, 2 and 3 flashing alternately. But obviously this is not allowing me to access LED's 4 through 9.


pinMode (6 , OUTPUT);
pinMode (10 , OUTPUT);
pinMode (11 , OUTPUT);
pinMode (12 , OUTPUT);

}
void loop ()
{
digitalWrite( 12 , HIGH); // sets led 1 on
digitalWrite ( 6 , LOW);
delay(1000);
digitalWrite( 12 , LOW); // sets led 1 off
digitalWrite ( 6 , HIGH);
delay(1000);
digitalWrite( 11 , HIGH); // sets led 2 on
digitalWrite ( 6 , LOW);
delay(1000);
digitalWrite( 11 , LOW); // sets led 2 off
digitalWrite ( 6 , HIGH);
delay(1000);
digitalWrite( 10 , HIGH); // sets led 3 on
digitalWrite ( 6 , LOW);
delay(1000);
digitalWrite( 10 , LOW); // sets led 3 off
digitalWrite ( 6 , HIGH);
delay(1000);
}

As I have previously stated I am a beginner at all this and I am suspecting that this problem has something to do with the last state of some of the pins as my circuit tests o.k. with straight analog input. It is all very confusing I must say and would appreciate it if someone could point me in the right direction.
Thanking you Pedro.